Skip to content

Commit a59d8cc

Browse files
ambarusgregkh
authored andcommitted
usb: gadget: f_fs: pull out f->disable() from ffs_func_set_alt()
The ``alt`` parameter was used as a way to differentiate between f->disable() and f->set_alt(). As the code paths diverge quite a bit, pull out the f->disable() code from ffs_func_set_alt(), everything will become clearer and less error prone. No change in functionality intended. Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org> Link: https://lore.kernel.org/r/20240802140428.2000312-3-tudor.ambarus@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 382b6ea commit a59d8cc

File tree

1 file changed

+22
-14
lines changed
  • drivers/usb/gadget/function

1 file changed

+22
-14
lines changed

drivers/usb/gadget/function/f_fs.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3731,14 +3731,12 @@ static int ffs_func_set_alt(struct usb_function *f,
37313731
struct ffs_data *ffs = func->ffs;
37323732
int ret = 0, intf;
37333733

3734-
if (alt != (unsigned)-1) {
3735-
if (alt > MAX_ALT_SETTINGS)
3736-
return -EINVAL;
3734+
if (alt > MAX_ALT_SETTINGS)
3735+
return -EINVAL;
37373736

3738-
intf = ffs_func_revmap_intf(func, interface);
3739-
if (intf < 0)
3740-
return intf;
3741-
}
3737+
intf = ffs_func_revmap_intf(func, interface);
3738+
if (intf < 0)
3739+
return intf;
37423740

37433741
if (ffs->func)
37443742
ffs_func_eps_disable(ffs->func);
@@ -3753,12 +3751,6 @@ static int ffs_func_set_alt(struct usb_function *f,
37533751
if (ffs->state != FFS_ACTIVE)
37543752
return -ENODEV;
37553753

3756-
if (alt == (unsigned)-1) {
3757-
ffs->func = NULL;
3758-
ffs_event_add(ffs, FUNCTIONFS_DISABLE);
3759-
return 0;
3760-
}
3761-
37623754
ffs->func = func;
37633755
ret = ffs_func_eps_enable(func);
37643756
if (ret >= 0) {
@@ -3770,7 +3762,23 @@ static int ffs_func_set_alt(struct usb_function *f,
37703762

37713763
static void ffs_func_disable(struct usb_function *f)
37723764
{
3773-
ffs_func_set_alt(f, 0, (unsigned)-1);
3765+
struct ffs_function *func = ffs_func_from_usb(f);
3766+
struct ffs_data *ffs = func->ffs;
3767+
3768+
if (ffs->func)
3769+
ffs_func_eps_disable(ffs->func);
3770+
3771+
if (ffs->state == FFS_DEACTIVATED) {
3772+
ffs->state = FFS_CLOSING;
3773+
INIT_WORK(&ffs->reset_work, ffs_reset_work);
3774+
schedule_work(&ffs->reset_work);
3775+
return;
3776+
}
3777+
3778+
if (ffs->state == FFS_ACTIVE) {
3779+
ffs->func = NULL;
3780+
ffs_event_add(ffs, FUNCTIONFS_DISABLE);
3781+
}
37743782
}
37753783

37763784
static int ffs_func_setup(struct usb_function *f,

0 commit comments

Comments
 (0)