Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754257AbbDHL3r (ORCPT ); Wed, 8 Apr 2015 07:29:47 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:47132 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754092AbbDHL3e (ORCPT ); Wed, 8 Apr 2015 07:29:34 -0400 X-AuditID: cbfee61a-f79516d000006302-34-5525111c6464 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 4/5] usb: gadget: mass_storage: Ensure that lun ids are contiguous Date: Wed, 08 Apr 2015 13:28:47 +0200 Message-id: <1428492528-11993-5-git-send-email-k.opasiak@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1428492528-11993-1-git-send-email-k.opasiak@samsung.com> References: <1428492528-11993-1-git-send-email-k.opasiak@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprBLMWRmVeSWpSXmKPExsVy+t9jQV1ZQdVQg4PbGC1mvWxnsTh4v96i efF6NouT576xWNyeOI3NYvP3DjaLy7vmsFksWtbKbLH2yF12B06PpxeDPPbPXcPu0bdlFaPH 8RvbmTw+b5ILYI3isklJzcksSy3St0vgyvi/eTtjwQzhiqMrbzI3MH7j72Lk4JAQMJH4+7ay i5ETyBSTuHBvPVsXIxeHkMB0RonpFxYyQji/GCW+TPnFCtLAJqAvMW+XKIgpIuAgcWZHEUgJ s8A2RomnO2awg8SFBUIkmqeagcxkEVCVePfsMiOIzSvgKvHt+lQmiLUKEnMm2YCEOQXcJB78 ncwGYgsBlXRfm8o2gZF3ASPDKkbR1ILkguKk9FxDveLE3OLSvHS95PzcTYzg8HomtYNxZYPF IUYBDkYlHl6BxSqhQqyJZcWVuYcYJTiYlUR4z3CphgrxpiRWVqUW5ccXleakFh9ilOZgURLn naMrFyokkJ5YkpqdmlqQWgSTZeLglGpgNPjAUXwz8sH87OvhTYZfRJ99/DRrZdADhqa5b06+ XHVZt4adhdfAbP97v06/wjCdNWYX5xkJvLC/Pm96o++RaWeyj/e8qudYlaG859qZ8/WVOi3F IUd0yzwSpzyr27lqsf/M2WdyLx6v7LmwaO6pq/t0nQJTP2yQvHT6W2Dvwici2xa94Dmz/aAS S3FGoqEWc1FxIgCM2Rm8KwIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2620 Lines: 86 Signed-off-by: Krzysztof Opasiak --- drivers/usb/gadget/function/f_mass_storage.c | 35 +++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 095b618..9d9fafb 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -3355,6 +3355,12 @@ static struct config_group *fsg_lun_make(struct config_group *group, goto out; } + if (!fsg_opts->common->luns[num - 1]) { + ret = -EINVAL; + pr_err("LUN ids should be contignous\n"); + goto out; + } + opts = kzalloc(sizeof(*opts), GFP_KERNEL); if (!opts) { ret = -ENOMEM; @@ -3364,12 +3370,17 @@ static struct config_group *fsg_lun_make(struct config_group *group, memset(&config, 0, sizeof(config)); config.removable = true; + /* ensure that lun ids are contiguous */ + ret = configfs_depend_item_unlocked(&(fsg_opts->lun_opts + [num - 1]->group.cg_item)); + if (ret) + goto err_free_opts; + ret = fsg_common_create_lun(fsg_opts->common, &config, num, name, (const char **)&group->cg_item.ci_name); - if (ret) { - kfree(opts); - goto out; - } + if (ret) + goto err_undepend_item; + opts->lun = fsg_opts->common->luns[num]; opts->lun_id = num; BUG_ON(fsg_opts->lun_opts[num]); @@ -3382,6 +3393,16 @@ static struct config_group *fsg_lun_make(struct config_group *group, out: mutex_unlock(&fsg_opts->lock); return ERR_PTR(ret); + +err_undepend_item: + configfs_undepend_item_unlocked(&(fsg_opts->lun_opts + [num - 1]->group.cg_item)); +err_free_opts: + kfree(opts); + + mutex_unlock(&fsg_opts->lock); + return ERR_PTR(ret); + } static void fsg_lun_drop(struct config_group *group, struct config_item *item) @@ -3400,10 +3421,16 @@ static void fsg_lun_drop(struct config_group *group, struct config_item *item) unregister_gadget_item(gadget); } + + /* Allow to remove next one */ + configfs_undepend_item_unlocked(&(fsg_opts->lun_opts + [lun_opts->lun_id - 1]->group.cg_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); config_item_put(item); -- 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/