aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Nazarewicz <mina86@mina86.com>2015-06-19 17:56:34 -0400
committerFelipe Balbi <balbi@ti.com>2015-07-06 13:34:08 -0400
commit8515bac01a983d277148e4fcc5f235bf603de577 (patch)
tree55abb371941f179e3abb3147d6949478b9fe229a
parent43cacb03aabe62158d8e5da876054c7d48fc9963 (diff)
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: Gregory CLEMENT <gregory.clement@free-electrons.com> Signed-off-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
-rw-r--r--drivers/usb/gadget/function/f_mass_storage.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
index d2259c663996..f936268d26c6 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -2786,7 +2786,7 @@ int fsg_common_set_nluns(struct fsg_common *common, int nluns)
2786 return -EINVAL; 2786 return -EINVAL;
2787 } 2787 }
2788 2788
2789 curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL); 2789 curlun = kcalloc(FSG_MAX_LUNS, sizeof(*curlun), GFP_KERNEL);
2790 if (unlikely(!curlun)) 2790 if (unlikely(!curlun))
2791 return -ENOMEM; 2791 return -ENOMEM;
2792 2792
@@ -2796,8 +2796,6 @@ int fsg_common_set_nluns(struct fsg_common *common, int nluns)
2796 common->luns = curlun; 2796 common->luns = curlun;
2797 common->nluns = nluns; 2797 common->nluns = nluns;
2798 2798
2799 pr_info("Number of LUNs=%d\n", common->nluns);
2800
2801 return 0; 2799 return 0;
2802} 2800}
2803EXPORT_SYMBOL_GPL(fsg_common_set_nluns); 2801EXPORT_SYMBOL_GPL(fsg_common_set_nluns);
@@ -3563,14 +3561,26 @@ static struct usb_function *fsg_alloc(struct usb_function_instance *fi)
3563 struct fsg_opts *opts = fsg_opts_from_func_inst(fi); 3561 struct fsg_opts *opts = fsg_opts_from_func_inst(fi);
3564 struct fsg_common *common = opts->common; 3562 struct fsg_common *common = opts->common;
3565 struct fsg_dev *fsg; 3563 struct fsg_dev *fsg;
3564 unsigned nluns, i;
3566 3565
3567 fsg = kzalloc(sizeof(*fsg), GFP_KERNEL); 3566 fsg = kzalloc(sizeof(*fsg), GFP_KERNEL);
3568 if (unlikely(!fsg)) 3567 if (unlikely(!fsg))
3569 return ERR_PTR(-ENOMEM); 3568 return ERR_PTR(-ENOMEM);
3570 3569
3571 mutex_lock(&opts->lock); 3570 mutex_lock(&opts->lock);
3571 if (!opts->refcnt) {
3572 for (nluns = i = 0; i < FSG_MAX_LUNS; ++i)
3573 if (common->luns[i])
3574 nluns = i + 1;
3575 if (!nluns)
3576 pr_warn("No LUNS defined, continuing anyway\n");
3577 else
3578 common->nluns = nluns;
3579 pr_info("Number of LUNs=%u\n", common->nluns);
3580 }
3572 opts->refcnt++; 3581 opts->refcnt++;
3573 mutex_unlock(&opts->lock); 3582 mutex_unlock(&opts->lock);
3583
3574 fsg->function.name = FSG_DRIVER_DESC; 3584 fsg->function.name = FSG_DRIVER_DESC;
3575 fsg->function.bind = fsg_bind; 3585 fsg->function.bind = fsg_bind;
3576 fsg->function.unbind = fsg_unbind; 3586 fsg->function.unbind = fsg_unbind;