On Mon, Jun 22 2015, Krzysztof Opasiak wrote: > 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> Acked-by: Michal Nazarewicz <mina86@xxxxxxxxxx> but then again I think that we should let user space shoot themselves in the foot if they want to, especially as letting them to that is less code. ;) > --- > 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 > -- 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