Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932266AbbDHO47 (ORCPT ); Wed, 8 Apr 2015 10:56:59 -0400 Received: from mailout4.w1.samsung.com ([210.118.77.14]:42782 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754251AbbDHO44 (ORCPT ); Wed, 8 Apr 2015 10:56:56 -0400 X-AuditID: cbfec7f5-b7f1e6d00000617c-2e-55254108b472 Message-id: <552541B4.4040905@samsung.com> Date: Wed, 08 Apr 2015 16:56:52 +0200 From: Krzysztof Opasiak User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-version: 1.0 To: Alan Stern Cc: balbi@ti.com, gregkh@linuxfoundation.org, jlbec@evilplan.org, andrzej.p@samsung.com, m.szyprowski@samsung.com, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: Re: [PATCH v2 2/4] usb: gadget: mass_storage: Store lun_opts in fsg_opts References: In-reply-to: Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrBLMWRmVeSWpSXmKPExsVy+t/xK7ocjqqhBr0LdSxmvWxnsTh4v96i efF6NouT576xWGz+3sFmcXnXHDaLRctamS3WHrnLbjHh9wU2B06PpxeDPPbPXcPuMfvuD0aP vi2rGD2O39jO5PF5k1wAWxSXTUpqTmZZapG+XQJXxtrnBxgLJgtXPG2exdTAuJO/i5GTQ0LA RGLexNMsELaYxIV769m6GLk4hASWMkrc7FvPDOF8YpTY+W8tM0gVr4CWxIzT84BsDg4WAVWJ VZNFQUw2AX2JebtEQSpEBSIk5h97DVUtKPFj8j2w+SJAnZubXoLFmQVOMkp0XGMFsYUFgiU6 7h5iAhkjJOAjsb5FFyTMKeArceTjY6hyW4kF79exQNjyEpvXvGWewCgwC8mGWUjKZiEpW8DI vIpRNLU0uaA4KT3XSK84Mbe4NC9dLzk/dxMjJPS/7mBceszqEKMAB6MSD6/HFZVQIdbEsuLK 3EOMEhzMSiK8Tx1UQ4V4UxIrq1KL8uOLSnNSiw8xMnFwSjUwmjWnhwfeWHzcucyIVdX1KKfc NcOcuP6adMmOQ612uw345n0o+7VzTe3f+IXPN4gW+93gUt196OC5LY/7b11RPhsRE/7sanFg 2Lcv95r58044Xvw0qytu9f0Qh7b576N45mp9SbiewaDQX783YOE15kK2+IsGdbEPkj6IbVku eVLPIq/gyVpNJZbijERDLeai4kQAWMeBhFsCAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2632 Lines: 69 Hi, On 04/08/2015 04:15 PM, Alan Stern wrote:> On Wed, 8 Apr 2015, Krzysztof Opasiak wrote: > >> Signed-off-by: Krzysztof Opasiak >> --- >> drivers/usb/gadget/function/f_mass_storage.c | 5 +++++ >> drivers/usb/gadget/function/f_mass_storage.h | 1 + >> 2 files changed, 6 insertions(+) >> >> diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c >> index 811929c..095b618 100644 >> --- a/drivers/usb/gadget/function/f_mass_storage.c >> +++ b/drivers/usb/gadget/function/f_mass_storage.c >> @@ -3372,6 +3372,8 @@ static struct config_group *fsg_lun_make(struct config_group *group, >> } >> opts->lun = fsg_opts->common->luns[num]; >> opts->lun_id = num; >> + BUG_ON(fsg_opts->lun_opts[num]); > > This is not a good idea. BUG_ON should hardly ever be used. In fact, > Linus has said that the only time BUG_ON should be used is when things > are so badly messed up that it is better to crash the computer than to > let it continue. > > What's wrong with using WARN_ON instead? Nothing. I have simply used BUG_ON() because this situation should never happen. If it happed then we made some mess in luns and there is no easy way to recovery from this point. This is only a little defense point for future to make debugging easier. I may change this to WARN_ON() if you like. > >> diff --git a/drivers/usb/gadget/function/f_mass_storage.h b/drivers/usb/gadget/function/f_mass_storage.h >> index b4866fc..0a7c656 100644 >> --- a/drivers/usb/gadget/function/f_mass_storage.h >> +++ b/drivers/usb/gadget/function/f_mass_storage.h >> @@ -81,6 +81,7 @@ struct fsg_opts { >> struct fsg_common *common; >> struct usb_function_instance func_inst; >> struct fsg_lun_opts lun0; >> + struct fsg_lun_opts *lun_opts[FSG_MAX_LUNS]; > > This looks strange. Why is the entry for LUN 0 duplicated? LUN 0 is created on mkdir and cannot be removed by user so the memory for it is allocated together with fsg_opts structure. Rest of LUNs are being created by explicit user action and malloc() separately. This array is used to store their pointers. To make the code easier we simply: lun_opts[0] = &fsg_opts->lun0; so later we don't care which lun we are dealing with. -- Best regards, Krzysztof Opasiak Samsung R&D Institute Poland Samsung Electronics -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/