On Thu, Nov 22 2012, Andrzej Pietrasiewicz wrote: > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@xxxxxxxxxxx> > Signed-off-by: Kyungmin Park <kyungmin.park@xxxxxxxxxxx> > --- > drivers/usb/gadget/f_mass_storage.c | 225 +++++++++++++++++++++++++++++++++++ > 1 files changed, 225 insertions(+), 0 deletions(-) > > diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c > index b244ddc..c9b9d06 100644 > --- a/drivers/usb/gadget/f_mass_storage.c > +++ b/drivers/usb/gadget/f_mass_storage.c > +static ssize_t fsg_common_show_luns(struct fsg_common *common, char *buf) > +{ > + return sprintf(buf, "%d\n", common->nluns); > +} > + > +static ssize_t fsg_common_store_luns(struct fsg_common *common, const char *buf, > + size_t count) > +{ > + struct config_item *function, *config, *gadget; > + struct dentry *parent, *new; > + char n[UFG_STR_LEN]; UFG_STR_LEN seems like an overkill considering that the strings will be up to 4 character long. ;) > + u16 tmp; > + char *p = (char *)buf; > + int rc; > + > + function = common->group.cg_item.ci_parent; > + if (!function) > + return -EBUSY; > + > + config = function->ci_parent; > + if (!config) > + return -EBUSY; > + > + gadget = config->ci_parent; > + if (!gadget) > + return -EBUSY; > + > + rc = kstrtou16(p, 10, &tmp); > + if (rc < 0) > + return rc; > + if (tmp > FSG_MAX_LUNS) > + return -ERANGE; > + > + common->nluns = tmp; > + parent = common->group.cg_item.ci_dentry; > + for (tmp = 0; tmp < common->nluns; tmp++) { > + struct qstr name; > + > + sprintf(n, "lun%d", tmp); > + name.name = n; > + name.len = strlen(name.name); > + name.hash = full_name_hash(name.name, name.len); > + > + new = d_alloc(parent, &name); > + if (IS_ERR_OR_NULL(new)) { > + rc = -ENOMEM; > + goto rollback; > + } > + d_add(new, NULL); > + rc = ufg_mkdir(parent, new); > + if (rc) { > + d_drop(new); > + dput(new); > + > + goto rollback; > + } > + dput(new); /* make the refcount 1 */ > + } > + > + return count; > + > +rollback: > + while (tmp--) { > + struct config_item *child; > + > + sprintf(n, "lun%d", tmp); > + child = config_group_find_item(&common->group, n); > + if (child) > + ufg_rmdir(parent, child->ci_dentry); > + > + } > + return rc; > +} -- Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michał “mina86” Nazarewicz (o o) ooo +----<email/xmpp: mpn@xxxxxxxxxx>--------------ooO--(_)--Ooo--
Attachment:
pgpTX7lO63ond.pgp
Description: PGP signature