Skip to content

Commit

Permalink
usb: gadget: f_fs: Add the missing get_alt callback
Browse files Browse the repository at this point in the history
The Apple CarLife iAP gadget has a descriptor in userspace with two
alternate settings. The host sends the set_alt request to configure
alt_setting 0 or 1, and this is verified by the subsequent get_alt
request.

This patch implements and sets the get_alt callback. Without the
get_alt callback, composite.c abruptly concludes the
USB_REQ_GET/SET_INTERFACE request, assuming only one alt setting
for the endpoint.

unlike the uvc and ncm, f_fs gadget is fully implemented in userspace,
and driver just reset the eps and generate the event. so no additional
adaptaion associated with this change is not required in set_alt callback

Signed-off-by: Hardik Gajjar <hgajjar@de.adit-jv.com>
Link: https://lore.kernel.org/r/20240301124708.120394-1-hgajjar@de.adit-jv.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Hardik Gajjar authored and Greg Kroah-Hartman committed Mar 26, 2024
1 parent f7a7f80 commit 2f55055
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion drivers/usb/gadget/function/f_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "configfs.h"

#define FUNCTIONFS_MAGIC 0xa647361 /* Chosen by a honest dice roll ;) */
#define MAX_ALT_SETTINGS 2 /* Allow up to 2 alt settings to be set. */

MODULE_IMPORT_NS(DMA_BUF);

Expand Down Expand Up @@ -80,6 +81,7 @@ struct ffs_function {
short *interfaces_nums;

struct usb_function function;
int cur_alt[MAX_CONFIG_INTERFACES];
};


Expand All @@ -103,6 +105,7 @@ static int __must_check ffs_func_eps_enable(struct ffs_function *func);
static int ffs_func_bind(struct usb_configuration *,
struct usb_function *);
static int ffs_func_set_alt(struct usb_function *, unsigned, unsigned);
static int ffs_func_get_alt(struct usb_function *f, unsigned int intf);
static void ffs_func_disable(struct usb_function *);
static int ffs_func_setup(struct usb_function *,
const struct usb_ctrlrequest *);
Expand Down Expand Up @@ -3704,13 +3707,25 @@ static void ffs_reset_work(struct work_struct *work)
ffs_data_reset(ffs);
}

static int ffs_func_get_alt(struct usb_function *f,
unsigned int interface)
{
struct ffs_function *func = ffs_func_from_usb(f);
int intf = ffs_func_revmap_intf(func, interface);

return (intf < 0) ? intf : func->cur_alt[interface];
}

static int ffs_func_set_alt(struct usb_function *f,
unsigned interface, unsigned alt)
{
struct ffs_function *func = ffs_func_from_usb(f);
struct ffs_data *ffs = func->ffs;
int ret = 0, intf;

if (alt > MAX_ALT_SETTINGS)
return -EINVAL;

if (alt != (unsigned)-1) {
intf = ffs_func_revmap_intf(func, interface);
if (intf < 0)
Expand Down Expand Up @@ -3738,8 +3753,10 @@ static int ffs_func_set_alt(struct usb_function *f,

ffs->func = func;
ret = ffs_func_eps_enable(func);
if (ret >= 0)
if (ret >= 0) {
ffs_event_add(ffs, FUNCTIONFS_ENABLE);
func->cur_alt[interface] = alt;
}
return ret;
}

Expand Down Expand Up @@ -4066,6 +4083,7 @@ static struct usb_function *ffs_alloc(struct usb_function_instance *fi)
func->function.bind = ffs_func_bind;
func->function.unbind = ffs_func_unbind;
func->function.set_alt = ffs_func_set_alt;
func->function.get_alt = ffs_func_get_alt;
func->function.disable = ffs_func_disable;
func->function.setup = ffs_func_setup;
func->function.req_match = ffs_func_req_match;
Expand Down

0 comments on commit 2f55055

Please sign in to comment.