> On 07/02/2015 09:14 PM, Felipe Balbi wrote: >> for the -rc cycle we need a minimal fix, though. Simplification, >> refactoring and whatever else, needs to be merged during merge window. On Thu, Jul 02 2015, Krzysztof Opasiak wrote: > Ok, sure. So the easiest way to fix problems in previously applied patch > would be as Michal suggested here: [1]. Putting 1 and 2 together should > be fine as a minimal fix for GET_MAX_LUNS issue. > > 1 - http://marc.info/?l=linux-usb&m=143585072403772&w=2 > 2 - http://marc.info/?l=linux-usb&m=143584114100542&w=2 Merged with the fix applied attached below. It should replace bf201db46beb30f58c38348cef837b461d6ac640 from your testing/fixes branch. The only difference to the previous version is change in call to kcalloc. >From 3b1fd1e556e6d64b48f9eb65b9921dbaef76bd95 Mon Sep 17 00:00:00 2001 From: Michal Nazarewicz <mina86@xxxxxxxxxx> Date: Fri, 19 Jun 2015 23:56:34 +0200 Subject: [PATCH] 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. Tested-by: Gregory CLEMENT <gregory.clement@xxxxxxxxxxxxxxxxxx> Signed-off-by: Michal Nazarewicz <mina86@xxxxxxxxxx> Cc: <stable@xxxxxxxxxxxxxxx> Signed-off-by: Felipe Balbi <balbi@xxxxxx> --- drivers/usb/gadget/function/f_mass_storage.c | 16 +++++++++++++--- 1 file 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 3cc109f..15c3071 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) return -EINVAL; } - curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL); + curlun = kcalloc(FSG_MAX_LUNS, sizeof(*curlun), GFP_KERNEL); if (unlikely(!curlun)) return -ENOMEM; @@ -2796,8 +2796,6 @@ int fsg_common_set_nluns(struct fsg_common *common, int nluns) common->luns = curlun; common->nluns = nluns; - pr_info("Number of LUNs=%d\n", common->nluns); - return 0; } EXPORT_SYMBOL_GPL(fsg_common_set_nluns); @@ -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_common *common = opts->common; struct fsg_dev *fsg; + unsigned nluns, i; fsg = kzalloc(sizeof(*fsg), GFP_KERNEL); if (unlikely(!fsg)) return ERR_PTR(-ENOMEM); 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++; mutex_unlock(&opts->lock); + fsg->function.name = FSG_DRIVER_DESC; fsg->function.bind = fsg_bind; fsg->function.unbind = fsg_unbind; -- 2.4.3.573.g4eafbef -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html