Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756307AbbDIQS5 (ORCPT ); Thu, 9 Apr 2015 12:18:57 -0400 Received: from mailout1.samsung.com ([203.254.224.24]:10617 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753196AbbDIQSw (ORCPT ); Thu, 9 Apr 2015 12:18:52 -0400 X-AuditID: cbfee61a-f79516d000006302-3d-5526a66acea1 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 3/4] usb: gadget: mass_storage: Ensure that lun ids are contiguous Date: Thu, 09 Apr 2015 18:18:09 +0200 Message-id: <1428596290-23637-4-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+t9jAd2sZWqhBjvec1nMetnOYnHwfr1F 8+L1bBYnz31jsbg9cRqbxebvHWwWl3fNYbNYtKyV2WLtkbvsDpweTy8Geeyfu4bdo2/LKkaP 4ze2M3l83iQXwBrFZZOSmpNZllqkb5fAlfH8+Sb2ghXiFedWNLI2MM4S7mLk5JAQMJH4ePck I4QtJnHh3nq2LkYuDiGBRYwSa+5OZoJwfjFKvN64nLmLkYODTUBfYt4uURBTRMBB4syOIpAS ZoFtjBJPd8xgBxkkLBAu8aZhF5jNIqAqsePsXrAFvAKuEjO33GcC6ZUQUJCYM8kGxOQUcJPo 65EGqRACqthx7BnjBEbeBYwMqxhFUwuSC4qT0nMN9YoTc4tL89L1kvNzNzGCA+yZ1A7GlQ0W hxgFOBiVeHhffFMNFWJNLCuuzD3EKMHBrCTC+3GhWqgQb0piZVVqUX58UWlOavEhRmkOFiVx 3jm6cqFCAumJJanZqakFqUUwWSYOTqkGxj1RnUZ+N3V93+ceKD6m+HzGc3PvJXdPFjV+kJ0Z nLXj02TFo6nint+dfvkf/Cj6Mfhxq8tkcTmH/fc+v7u2Wa0yNir3p+Gml4LH5x+vsef0OuKX lTaBa8drf5P9xh0ukxL/XhIRqeP8p6+8X0jsbWvKlwMvPL1MVnPMv3j8QqLvbKNfwYaZJUos xRmJhlrMRcWJAAypiDcsAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3130 Lines: 104 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)." This commit fix configfs interface adding this restriction. Now user can create luns only with contignous ids and cannot remove lun from the middle of id space. Example: as is: $ mkdir mass_storage.name $ mkdir lun.3 $ mkdir lun.5 $ rmdir lun.3 After this commit: $ mkdir mass_storage.name $ mkdir lun.3 mkdir: cannot create directory 'lun.3': Invalid argument $ mkdir lun.1 $ mkdir lun.2 $ rmdir lun.1 rmdir: failed to remove 'lun.1': Device or resource busy $ rmdir lun.2 $ rmdir lun.1 Signed-off-by: Krzysztof Opasiak --- drivers/usb/gadget/function/f_mass_storage.c | 29 ++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 67a67b5..f4b2de4 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 contiguous\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; WARN_ON(fsg_opts->lun_opts[num]); @@ -3379,6 +3390,12 @@ static struct config_group *fsg_lun_make(struct config_group *group, config_group_init_type_name(&opts->group, name, &fsg_lun_type); return &opts->group; + +err_undepend_item: + configfs_undepend_item_unlocked(&(fsg_opts->lun_opts + [num - 1]->group.cg_item)); +err_free_opts: + kfree(opts); out: mutex_unlock(&fsg_opts->lock); return ERR_PTR(ret); @@ -3400,6 +3417,10 @@ 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; -- 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/