[PATCH 2/5] usb: gadget: mass_storage: Enforce contiguous LUN ids

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

 



According to mass storage specification:

"Logical Unit Numbers on the device shall be numbered contiguously
 starting from LUN 0 to a maximum LUN of 15 (Fh)"

So don't allow to bind ms function unless we have at least LUN0
and LUNs ids are contiguous.

Signed-off-by: Krzysztof Opasiak <k.opasiak@xxxxxxxxxxx>
---
 drivers/usb/gadget/function/f_mass_storage.c |   29 ++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
index 2e8f37e..19b31d7 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -3065,6 +3065,35 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
 	int			ret;
 	struct fsg_opts		*opts;
 
+	/*
+	 * Don't allow to bind if we don't have at least one LUN
+	 * or LUNs ids are not contiguous.
+	 */
+	if (likely(common->luns)) {
+		bool found_null = false;
+
+		for (i = 0; i < common->nluns; ++i) {
+			if (!common->luns[i]) {
+				found_null = true;
+				continue;
+			}
+
+			if (!found_null) {
+				continue;
+			} else {
+				pr_err("LUN ids should be contiguous.\n");
+				return -EINVAL;
+			}
+		}
+
+		if (i == 0 || !common->luns[i]) {
+			pr_err("There should be at least one LUN.\n");
+			return -EINVAL;
+		}
+	} else {
+		return -EINVAL;
+	}
+
 	opts = fsg_opts_from_func_inst(f->fi);
 	if (!opts->no_configfs) {
 		ret = fsg_common_set_cdev(fsg->common, c->cdev,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe stable" in



[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]