提交 8515bac0 编写于 作者: M Michal Nazarewicz 提交者: Felipe Balbi

usb: f_mass_storage: limit number of reported LUNs

Mass storage function created via configfs always reports eight LUNs
to the hosts even if only one LUN has been configured.  Adjust the
number when the USB function is allocated based on LUNs that user
has created.

Cc: <stable@vger.kernel.org>
Tested-by: NGregory CLEMENT <gregory.clement@free-electrons.com>
Signed-off-by: NMichal Nazarewicz <mina86@mina86.com>
Signed-off-by: NFelipe Balbi <balbi@ti.com>
上级 43cacb03
...@@ -2786,7 +2786,7 @@ int fsg_common_set_nluns(struct fsg_common *common, int nluns) ...@@ -2786,7 +2786,7 @@ int fsg_common_set_nluns(struct fsg_common *common, int nluns)
return -EINVAL; return -EINVAL;
} }
curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL); curlun = kcalloc(FSG_MAX_LUNS, sizeof(*curlun), GFP_KERNEL);
if (unlikely(!curlun)) if (unlikely(!curlun))
return -ENOMEM; return -ENOMEM;
...@@ -2796,8 +2796,6 @@ int fsg_common_set_nluns(struct fsg_common *common, int nluns) ...@@ -2796,8 +2796,6 @@ int fsg_common_set_nluns(struct fsg_common *common, int nluns)
common->luns = curlun; common->luns = curlun;
common->nluns = nluns; common->nluns = nluns;
pr_info("Number of LUNs=%d\n", common->nluns);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(fsg_common_set_nluns); EXPORT_SYMBOL_GPL(fsg_common_set_nluns);
...@@ -3563,14 +3561,26 @@ static struct usb_function *fsg_alloc(struct usb_function_instance *fi) ...@@ -3563,14 +3561,26 @@ static struct usb_function *fsg_alloc(struct usb_function_instance *fi)
struct fsg_opts *opts = fsg_opts_from_func_inst(fi); struct fsg_opts *opts = fsg_opts_from_func_inst(fi);
struct fsg_common *common = opts->common; struct fsg_common *common = opts->common;
struct fsg_dev *fsg; struct fsg_dev *fsg;
unsigned nluns, i;
fsg = kzalloc(sizeof(*fsg), GFP_KERNEL); fsg = kzalloc(sizeof(*fsg), GFP_KERNEL);
if (unlikely(!fsg)) if (unlikely(!fsg))
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
mutex_lock(&opts->lock); mutex_lock(&opts->lock);
if (!opts->refcnt) {
for (nluns = i = 0; i < FSG_MAX_LUNS; ++i)
if (common->luns[i])
nluns = i + 1;
if (!nluns)
pr_warn("No LUNS defined, continuing anyway\n");
else
common->nluns = nluns;
pr_info("Number of LUNs=%u\n", common->nluns);
}
opts->refcnt++; opts->refcnt++;
mutex_unlock(&opts->lock); mutex_unlock(&opts->lock);
fsg->function.name = FSG_DRIVER_DESC; fsg->function.name = FSG_DRIVER_DESC;
fsg->function.bind = fsg_bind; fsg->function.bind = fsg_bind;
fsg->function.unbind = fsg_unbind; fsg->function.unbind = fsg_unbind;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册