Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756362AbbDIQTk (ORCPT ); Thu, 9 Apr 2015 12:19:40 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:40485 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756082AbbDIQSs (ORCPT ); Thu, 9 Apr 2015 12:18:48 -0400 X-AuditID: cbfee61b-f79536d000000f1f-d6-5526a6663eb5 From: Krzysztof Opasiak To: balbi@ti.com, gregkh@linuxfoundation.org, jlbec@evilplan.org Cc: andrzej.p@samsung.com, m.szyprowski@samsung.com, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Krzysztof Opasiak Subject: [PATCH v3 2/4] usb: gadget: mass_storage: Store lun_opts in fsg_opts Date: Thu, 09 Apr 2015 18:18:08 +0200 Message-id: <1428596290-23637-3-git-send-email-k.opasiak@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1428596290-23637-1-git-send-email-k.opasiak@samsung.com> References: <1428596290-23637-1-git-send-email-k.opasiak@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprJLMWRmVeSWpSXmKPExsVy+t9jAd20ZWqhBgv/6FjMetnOYnHwfr1F 8+L1bBYnz31jsbg9cRqbxebvHWwWl3fNYbNYtKyV2WLtkbvsDpweTy8Geeyfu4bdo2/LKkaP 4ze2M3l83iQXwBrFZZOSmpNZllqkb5fAlbFp4RTmgsuiFf8vrGZqYLwt1MXIySEhYCIx4fVi NghbTOLCvfVANheHkMAiRomJuy9DOb8YJTo+fmbtYuTgYBPQl5i3SxTEFBFwkDizowikhFlg G6PE0x0z2EEGCQv4Shyb3wI2lEVAVWLxy2WsIDavgKvE0QOdYGMkBBQk5kyyATE5Bdwk+nqk QSqEgCp2HHvGOIGRdwEjwypG0dSC5ILipPRcI73ixNzi0rx0veT83E2M4AB7Jr2DcVWDxSFG AQ5GJR7eF99UQ4VYE8uKK3MPMUpwMCuJ8H5cqBYqxJuSWFmVWpQfX1Sak1p8iFGag0VJnHeO rlyokEB6YklqdmpqQWoRTJaJg1OqgbGqmsXrlbr7lmtiCa3SCTZv+Ap0mFinnGDQKuu99f6w U0HjoSnbSjZe5zLYa3tDNUUgeMP5Les7Aiw+pn77GG9l36jy7Orqf48mTNLjtfp2TnqCEsMf Oac0pUP7K5fu3fzOYOMNBZm/Nr4eLa8XP3n9eX7Ygt+1WwvP1uz4yWe65uAEpdw5KdZKLMUZ iYZazEXFiQBL0u9oLAIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2949 Lines: 72 Currently lun_opts are stored only in configfs and accessed using container_of() on config group. This means that in configfs callbacks we can easily access only current lun (config_group). This commit adds an additinal array to fsg_opts which allows to access not only current lun but also all other luns using their id. 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..67a67b5 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; + WARN_ON(fsg_opts->lun_opts[num]); + fsg_opts->lun_opts[num] = opts; mutex_unlock(&fsg_opts->lock); config_group_init_type_name(&opts->group, name, &fsg_lun_type); @@ -3400,6 +3402,7 @@ static void fsg_lun_drop(struct config_group *group, struct config_item *item) fsg_common_remove_lun(lun_opts->lun, fsg_opts->common->sysfs); fsg_opts->common->luns[lun_opts->lun_id] = NULL; + fsg_opts->lun_opts[lun_opts->lun_id] = NULL; lun_opts->lun_id = 0; mutex_unlock(&fsg_opts->lock); @@ -3546,6 +3549,7 @@ static struct usb_function_instance *fsg_alloc_inst(void) if (!opts) return ERR_PTR(-ENOMEM); mutex_init(&opts->lock); + memset(opts->lun_opts, 0, sizeof(opts->lun_opts)); opts->func_inst.free_func_inst = fsg_free_inst; opts->common = fsg_common_setup(opts->common); if (IS_ERR(opts->common)) { @@ -3569,6 +3573,7 @@ static struct usb_function_instance *fsg_alloc_inst(void) (const char **)&opts->func_inst.group.cg_item.ci_name); opts->lun0.lun = opts->common->luns[0]; opts->lun0.lun_id = 0; + opts->lun_opts[0] = &opts->lun0; config_group_init_type_name(&opts->lun0.group, "lun.0", &fsg_lun_type); opts->default_groups[0] = &opts->lun0.group; opts->func_inst.group.default_groups = opts->default_groups; 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]; struct config_group *default_groups[2]; bool no_configfs; /* for legacy gadgets */ -- 1.7.9.5 -- 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/