lkml.org 
[lkml]   [2015]   [Jul]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 4.1 105/267] usb: f_mass_storage: limit number of reported LUNs
    Date
    4.1-stable review patch.  If anyone has any objections, please let me know.

    ------------------

    From: Michal Nazarewicz <mina86@mina86.com>

    commit 8515bac01a983d277148e4fcc5f235bf603de577 upstream.

    Mass storage function created via configfs always reports eight LUNs
    to the hosts even if only one LUN has been configured. Adjust the
    number when the USB function is allocated based on LUNs that user
    has created.

    Tested-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
    Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
    Signed-off-by: Felipe Balbi <balbi@ti.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

    ---
    drivers/usb/gadget/function/f_mass_storage.c | 16 +++++++++++++---
    1 file changed, 13 insertions(+), 3 deletions(-)

    --- a/drivers/usb/gadget/function/f_mass_storage.c
    +++ b/drivers/usb/gadget/function/f_mass_storage.c
    @@ -2786,7 +2786,7 @@ int fsg_common_set_nluns(struct fsg_comm
    return -EINVAL;
    }

    - curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL);
    + curlun = kcalloc(FSG_MAX_LUNS, sizeof(*curlun), GFP_KERNEL);
    if (unlikely(!curlun))
    return -ENOMEM;

    @@ -2796,8 +2796,6 @@ int fsg_common_set_nluns(struct fsg_comm
    common->luns = curlun;
    common->nluns = nluns;

    - pr_info("Number of LUNs=%d\n", common->nluns);
    -
    return 0;
    }
    EXPORT_SYMBOL_GPL(fsg_common_set_nluns);
    @@ -3563,14 +3561,26 @@ static struct usb_function *fsg_alloc(st
    struct fsg_opts *opts = fsg_opts_from_func_inst(fi);
    struct fsg_common *common = opts->common;
    struct fsg_dev *fsg;
    + unsigned nluns, i;

    fsg = kzalloc(sizeof(*fsg), GFP_KERNEL);
    if (unlikely(!fsg))
    return ERR_PTR(-ENOMEM);

    mutex_lock(&opts->lock);
    + if (!opts->refcnt) {
    + for (nluns = i = 0; i < FSG_MAX_LUNS; ++i)
    + if (common->luns[i])
    + nluns = i + 1;
    + if (!nluns)
    + pr_warn("No LUNS defined, continuing anyway\n");
    + else
    + common->nluns = nluns;
    + pr_info("Number of LUNs=%u\n", common->nluns);
    + }
    opts->refcnt++;
    mutex_unlock(&opts->lock);
    +
    fsg->function.name = FSG_DRIVER_DESC;
    fsg->function.bind = fsg_bind;
    fsg->function.unbind = fsg_unbind;



    \
     
     \ /
      Last update: 2015-07-31 22:21    [W:2.262 / U:0.032 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site