Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: f_fs: add extra check before unregister_gadget_item

ffs_closed can race with configfs_rmdir which will call config_item_release, so
add an extra check to avoid calling the unregister_gadget_item with an null
gadget item.

Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
Signed-off-by: Felipe Balbi <balbi@ti.com>

authored by

Rui Miguel Silva and committed by
Felipe Balbi
f14e9ad1 76e838c9

+8 -2
+8 -2
drivers/usb/gadget/function/f_fs.c
··· 3433 3433 static void ffs_closed(struct ffs_data *ffs) 3434 3434 { 3435 3435 struct ffs_dev *ffs_obj; 3436 + struct f_fs_opts *opts; 3436 3437 3437 3438 ENTER(); 3438 3439 ffs_dev_lock(); ··· 3447 3446 if (ffs_obj->ffs_closed_callback) 3448 3447 ffs_obj->ffs_closed_callback(ffs); 3449 3448 3450 - if (!ffs_obj->opts || ffs_obj->opts->no_configfs 3451 - || !ffs_obj->opts->func_inst.group.cg_item.ci_parent) 3449 + if (ffs_obj->opts) 3450 + opts = ffs_obj->opts; 3451 + else 3452 + goto done; 3453 + 3454 + if (opts->no_configfs || !opts->func_inst.group.cg_item.ci_parent 3455 + || !atomic_read(&opts->func_inst.group.cg_item.ci_kref.refcount)) 3452 3456 goto done; 3453 3457 3454 3458 unregister_gadget_item(ffs_obj->opts->