Reapply "usb: gadget: f_fs: Add the missing get_alt callback"

This reverts commit 551c6efeb2.

The Pixel panic during USB disconnection should be fixed now.

Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: Ic23f18f30c0b3ae2648f6d6348bd9caed864fdc9
This commit is contained in:
Lee Jones
2024-09-25 10:35:02 +01:00
committed by Treehugger Robot
parent 2abc9bdfb0
commit d56bde2ef4
+19 -1
View File
@@ -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. */
#define DMABUF_ENQUEUE_TIMEOUT_MS 5000
@@ -82,6 +83,7 @@ struct ffs_function {
short *interfaces_nums;
struct usb_function function;
int cur_alt[MAX_CONFIG_INTERFACES];
};
@@ -105,6 +107,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 *);
@@ -3712,6 +3715,15 @@ 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)
{
@@ -3723,6 +3735,9 @@ static int ffs_func_set_alt(struct usb_function *f,
if (intf < 0)
return intf;
if (alt > MAX_ALT_SETTINGS)
return -EINVAL;
if (ffs->func)
ffs_func_eps_disable(ffs->func);
@@ -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;
}
@@ -4082,6 +4099,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;