Re: Viewing many gadgets in error under Windows with mass storage function and configfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On Thu, Jul 02, 2015 at 12:51:54PM +0200, Gregory CLEMENT wrote:
>> When I use configs to configure the mass storage function for the
>> gadget, and when the device is plugged under Windows, then the
>> partition that I expose is well managed, but I also see 7 other gadget
>> in the device manager with error.
>> 
>> This seven bogus gadget seems to be the 7 other LUN that are not
>> used. Indeed if I apply this dirty patch:
>> 
>> diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
>> index 3cc109f..2b4ae98 100644
>> --- a/drivers/usb/gadget/function/f_mass_storage.c
>> +++ b/drivers/usb/gadget/function/f_mass_storage.c
>> @@ -3511,7 +3511,8 @@ static struct usb_function_instance *fsg_alloc_inst(void)
>>                 rc = PTR_ERR(opts->common);
>>                 goto release_opts;
>>         }
>> -       rc = fsg_common_set_nluns(opts->common, FSG_MAX_LUNS);
>> +//     rc = fsg_common_set_nluns(opts->common, FSG_MAX_LUNS);
>> +       rc = fsg_common_set_nluns(opts->common, 1);
>>         if (rc)
>>                 goto release_opts;
>> 
>> Then there is no more gadget error under Windows. As the value of
>> FSG_MAX_LUNS is 8 and in my configuration I only use one partition,
>> then it makes sens that I see 7 bogus gadgets.
>> 
>> I also saw that in the legacy driver, it was possible to modify the
>> number of LUN using the module parameter file_count.

On Thu, Jul 02 2015, Felipe Balbi wrote:
> This has been reported. Michal was working on a fix, but the patch
> hasn't been applied yet.

I’ve came up with [1], which you should feel free to test, but then
Krzysztof came along with [2], which among other things addressed the
LUN count issue, and I kind of stopped working on the issue waiting for
his follow up.

Since merge window is about to close, perhaps the solution is to get [1]
merged quickly so it shows up in 4.2 and then get approaches described
in [3] for the future.

[1]
<http://news.gmane.org/find-root.php?message_id=xa1toak7j1rl.fsf%40mina86.com>,
patch also attached at the end of the message
[2] <http://news.gmane.org/find-root.php?message_id=1434979163%2d5942%2d1%2dgit%2dsend%2demail%2dk.opasiak%40samsung.com>
[3] <http://news.gmane.org/find-root.php?message_id=xa1t7fqvizh0.fsf%40mina86.com>

--------- >8 -----------------------------------------------------------
>From 59b6ec98aa9c638f7d140ad0b6b5a30bb2ba4145 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.

Signed-off-by: Michal Nazarewicz <mina86@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
---
 drivers/usb/gadget/function/f_mass_storage.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
index 3cc109f..e1beb14 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -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;

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@xxxxxxxxxx>--<xmpp:mina86@xxxxxxxxxx>--ooO--(_)--Ooo--
--
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



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux