From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f181.google.com ([209.85.212.181]:36672 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750947AbbFVObX convert rfc822-to-8bit (ORCPT ); Mon, 22 Jun 2015 10:31:23 -0400 Received: by wicnd19 with SMTP id nd19so78562601wic.1 for ; Mon, 22 Jun 2015 07:31:22 -0700 (PDT) From: Michal Nazarewicz To: Krzysztof Opasiak , balbi@ti.com Cc: stable@vger.kernel.org, david.fisher1@synopsys.com, gregkh@linuxfoundation.org, andrzej.p@samsung.com, m.szyprowski@samsung.com, linux-usb@vger.kernel.org, Krzysztof Opasiak Subject: Re: [PATCH 2/5] usb: gadget: mass_storage: Enforce contiguous LUN ids In-Reply-To: <1434979163-5942-3-git-send-email-k.opasiak@samsung.com> References: <1434979163-5942-1-git-send-email-k.opasiak@samsung.com> <1434979163-5942-3-git-send-email-k.opasiak@samsung.com> Date: Mon, 22 Jun 2015 16:31:17 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: stable-owner@vger.kernel.org List-ID: 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 Acked-by: Michal Nazarewicz 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 +------ooO--(_)--Ooo-- -- To unsubscribe from this list: send the line "unsubscribe stable" in