]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.0.8/usb-gadget-f_fs-add-extra-check-before-unregister_gadget_item.patch
5.0-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.0.8 / usb-gadget-f_fs-add-extra-check-before-unregister_gadget_item.patch
1 From f14e9ad17f46051b02bffffac2036486097de19e Mon Sep 17 00:00:00 2001
2 From: Rui Miguel Silva <rui.silva@linaro.org>
3 Date: Wed, 20 May 2015 14:52:40 +0100
4 Subject: usb: gadget: f_fs: add extra check before unregister_gadget_item
5
6 From: Rui Miguel Silva <rui.silva@linaro.org>
7
8 commit f14e9ad17f46051b02bffffac2036486097de19e upstream.
9
10 ffs_closed can race with configfs_rmdir which will call config_item_release, so
11 add an extra check to avoid calling the unregister_gadget_item with an null
12 gadget item.
13
14 Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
15 Signed-off-by: Felipe Balbi <balbi@ti.com>
16 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
17
18 ---
19 drivers/usb/gadget/function/f_fs.c | 10 ++++++++--
20 1 file changed, 8 insertions(+), 2 deletions(-)
21
22 --- a/drivers/usb/gadget/function/f_fs.c
23 +++ b/drivers/usb/gadget/function/f_fs.c
24 @@ -3433,6 +3433,7 @@ done:
25 static void ffs_closed(struct ffs_data *ffs)
26 {
27 struct ffs_dev *ffs_obj;
28 + struct f_fs_opts *opts;
29
30 ENTER();
31 ffs_dev_lock();
32 @@ -3446,8 +3447,13 @@ static void ffs_closed(struct ffs_data *
33 if (ffs_obj->ffs_closed_callback)
34 ffs_obj->ffs_closed_callback(ffs);
35
36 - if (!ffs_obj->opts || ffs_obj->opts->no_configfs
37 - || !ffs_obj->opts->func_inst.group.cg_item.ci_parent)
38 + if (ffs_obj->opts)
39 + opts = ffs_obj->opts;
40 + else
41 + goto done;
42 +
43 + if (opts->no_configfs || !opts->func_inst.group.cg_item.ci_parent
44 + || !atomic_read(&opts->func_inst.group.cg_item.ci_kref.refcount))
45 goto done;
46
47 unregister_gadget_item(ffs_obj->opts->