It prepare to improve pr_vdebug() which will show dev_name when multiple f_fs instance exist. Signed-off-by: Linyu Yuan <quic_linyyuan@xxxxxxxxxxx> --- v2: split to several changes according to v1 comments v1: https://lore.kernel.org/linux-usb/1679481369-30094-1-git-send-email-quic_linyyuan@xxxxxxxxxxx/ drivers/usb/gadget/function/f_fs.c | 78 +++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 40 deletions(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 8830847..a4051c8 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -231,7 +231,6 @@ struct ffs_io_data { }; struct ffs_desc_helper { - struct ffs_data *ffs; unsigned interfaces_count; unsigned eps_count; }; @@ -260,7 +259,7 @@ static void ffs_closed(struct ffs_data *ffs); static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock) __attribute__((warn_unused_result, nonnull)); -static char *ffs_prepare_buffer(const char __user *buf, size_t len) +static char *ffs_prepare_buffer(struct ffs_data *ffs, const char __user *buf, size_t len) __attribute__((warn_unused_result, nonnull)); @@ -354,7 +353,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, break; } - data = ffs_prepare_buffer(buf, len); + data = ffs_prepare_buffer(ffs, buf, len); if (IS_ERR(data)) { ret = PTR_ERR(data); break; @@ -426,7 +425,7 @@ static ssize_t ffs_ep0_write(struct file *file, const char __user *buf, spin_unlock_irq(&ffs->ev.waitq.lock); - data = ffs_prepare_buffer(buf, len); + data = ffs_prepare_buffer(ffs, buf, len); if (IS_ERR(data)) { ret = PTR_ERR(data); break; @@ -713,7 +712,8 @@ static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req) complete(&io_data->done); } -static ssize_t ffs_copy_to_iter(void *data, int data_len, struct iov_iter *iter) +static ssize_t ffs_copy_to_iter(struct ffs_data *ffs, void *data, int data_len, + struct iov_iter *iter) { ssize_t ret = copy_to_iter(data, data_len, iter); if (ret == data_len) @@ -824,7 +824,7 @@ static void ffs_user_copy_worker(struct work_struct *work) if (io_data->read && ret > 0) { kthread_use_mm(io_data->mm); - ret = ffs_copy_to_iter(io_data->buf, ret, &io_data->data); + ret = ffs_copy_to_iter(io_data->ffs, io_data->buf, ret, &io_data->data); kthread_unuse_mm(io_data->mm); } @@ -1984,16 +1984,16 @@ enum ffs_os_desc_type { FFS_OS_DESC, FFS_OS_DESC_EXT_COMPAT, FFS_OS_DESC_EXT_PROP }; -typedef int (*ffs_entity_callback)(enum ffs_entity_type entity, +typedef int (*ffs_entity_callback)(struct ffs_data *ffs, enum ffs_entity_type entity, u8 *valuep, struct usb_descriptor_header *desc, void *priv); -typedef int (*ffs_os_desc_callback)(enum ffs_os_desc_type entity, +typedef int (*ffs_os_desc_callback)(struct ffs_data *ffs, enum ffs_os_desc_type entity, struct usb_os_desc_header *h, void *data, unsigned len, void *priv); -static int __must_check ffs_do_single_desc(char *data, unsigned len, +static int __must_check ffs_do_single_desc(struct ffs_data *ffs, char *data, unsigned len, ffs_entity_callback entity, void *priv, int *current_class) { @@ -2023,7 +2023,7 @@ static int __must_check ffs_do_single_desc(char *data, unsigned len, pr_vdebug("invalid entity's value\n"); \ return -EINVAL; \ } \ - ret = entity(FFS_ ##type, &val, _ds, priv); \ + ret = entity(ffs, FFS_ ##type, &val, _ds, priv); \ if (ret < 0) { \ pr_debug("entity " #type "(%02x); ret = %d\n", \ (val), ret); \ @@ -2132,7 +2132,7 @@ static int __must_check ffs_do_single_desc(char *data, unsigned len, return length; } -static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, +static int __must_check ffs_do_descs(struct ffs_data *ffs, unsigned count, char *data, unsigned len, ffs_entity_callback entity, void *priv) { const unsigned _len = len; @@ -2146,7 +2146,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, data = NULL; /* Record "descriptor" entity */ - ret = entity(FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv); + ret = entity(ffs, FFS_DESCRIPTOR, (u8 *)num, (void *)data, priv); if (ret < 0) { pr_debug("entity DESCRIPTOR(%02lx); ret = %d\n", num, ret); @@ -2156,7 +2156,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, if (!data) return _len - len; - ret = ffs_do_single_desc(data, len, entity, priv, + ret = ffs_do_single_desc(ffs, data, len, entity, priv, ¤t_class); if (ret < 0) { pr_debug("%s returns %d\n", __func__, ret); @@ -2169,7 +2169,7 @@ static int __must_check ffs_do_descs(unsigned count, char *data, unsigned len, } } -static int __ffs_data_do_entity(enum ffs_entity_type type, +static int __ffs_data_do_entity(struct ffs_data *ffs, enum ffs_entity_type type, u8 *valuep, struct usb_descriptor_header *desc, void *priv) { @@ -2195,8 +2195,8 @@ static int __ffs_data_do_entity(enum ffs_entity_type type, * Strings are indexed from 1 (0 is reserved * for languages list) */ - if (*valuep > helper->ffs->strings_count) - helper->ffs->strings_count = *valuep; + if (*valuep > ffs->strings_count) + ffs->strings_count = *valuep; break; case FFS_ENDPOINT: @@ -2205,10 +2205,10 @@ static int __ffs_data_do_entity(enum ffs_entity_type type, if (helper->eps_count >= FFS_MAX_EPS_COUNT) return -EINVAL; /* Check if descriptors for any speed were already parsed */ - if (!helper->ffs->eps_count && !helper->ffs->interfaces_count) - helper->ffs->eps_addrmap[helper->eps_count] = + if (!ffs->eps_count && !ffs->interfaces_count) + ffs->eps_addrmap[helper->eps_count] = d->bEndpointAddress; - else if (helper->ffs->eps_addrmap[helper->eps_count] != + else if (ffs->eps_addrmap[helper->eps_count] != d->bEndpointAddress) return -EINVAL; break; @@ -2217,7 +2217,7 @@ static int __ffs_data_do_entity(enum ffs_entity_type type, return 0; } -static int __ffs_do_os_desc_header(enum ffs_os_desc_type *next_type, +static int __ffs_do_os_desc_header(struct ffs_data *ffs, enum ffs_os_desc_type *next_type, struct usb_os_desc_header *desc) { u16 bcd_version = le16_to_cpu(desc->bcdVersion); @@ -2250,7 +2250,7 @@ static int __ffs_do_os_desc_header(enum ffs_os_desc_type *next_type, * Process all extended compatibility/extended property descriptors * of a feature descriptor */ -static int __must_check ffs_do_single_os_desc(char *data, unsigned len, +static int __must_check ffs_do_single_os_desc(struct ffs_data *ffs, char *data, unsigned len, enum ffs_os_desc_type type, u16 feature_count, ffs_os_desc_callback entity, @@ -2262,7 +2262,7 @@ static int __must_check ffs_do_single_os_desc(char *data, unsigned len, /* loop over all ext compat/ext prop descriptors */ while (feature_count--) { - ret = entity(type, h, data, len, priv); + ret = entity(ffs, type, h, data, len, priv); if (ret < 0) { pr_debug("bad OS descriptor, type: %d\n", type); return ret; @@ -2274,7 +2274,7 @@ static int __must_check ffs_do_single_os_desc(char *data, unsigned len, } /* Process a number of complete Feature Descriptors (Ext Compat or Ext Prop) */ -static int __must_check ffs_do_os_descs(unsigned count, +static int __must_check ffs_do_os_descs(struct ffs_data *ffs, unsigned count, char *data, unsigned len, ffs_os_desc_callback entity, void *priv) { @@ -2300,7 +2300,7 @@ static int __must_check ffs_do_os_descs(unsigned count, if (le32_to_cpu(desc->dwLength) > len) return -EINVAL; - ret = __ffs_do_os_desc_header(&type, desc); + ret = __ffs_do_os_desc_header(ffs, &type, desc); if (ret < 0) { pr_debug("entity OS_DESCRIPTOR(%02lx); ret = %d\n", num, ret); @@ -2320,7 +2320,7 @@ static int __must_check ffs_do_os_descs(unsigned count, * Process all function/property descriptors * of this Feature Descriptor */ - ret = ffs_do_single_os_desc(data, len, type, + ret = ffs_do_single_os_desc(ffs, data, len, type, feature_count, entity, priv, desc); if (ret < 0) { pr_debug("%s returns %d\n", __func__, ret); @@ -2336,11 +2336,10 @@ static int __must_check ffs_do_os_descs(unsigned count, /* * Validate contents of the buffer from userspace related to OS descriptors. */ -static int __ffs_data_do_os_desc(enum ffs_os_desc_type type, +static int __ffs_data_do_os_desc(struct ffs_data *ffs, enum ffs_os_desc_type type, struct usb_os_desc_header *h, void *data, unsigned len, void *priv) { - struct ffs_data *ffs = priv; u8 length; switch (type) { @@ -2485,13 +2484,12 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, /* Read descriptors */ raw_descs = data; - helper.ffs = ffs; for (i = 0; i < 3; ++i) { if (!counts[i]) continue; helper.interfaces_count = 0; helper.eps_count = 0; - ret = ffs_do_descs(counts[i], data, len, + ret = ffs_do_descs(ffs, counts[i], data, len, __ffs_data_do_entity, &helper); if (ret < 0) goto error; @@ -2512,8 +2510,8 @@ static int __ffs_data_got_descs(struct ffs_data *ffs, len -= ret; } if (os_descs_count) { - ret = ffs_do_os_descs(os_descs_count, data, len, - __ffs_data_do_os_desc, ffs); + ret = ffs_do_os_descs(ffs, os_descs_count, data, len, + __ffs_data_do_os_desc, NULL); if (ret < 0) goto error; data += ret; @@ -2763,7 +2761,7 @@ static int ffs_ep_addr2idx(struct ffs_data *ffs, u8 endpoint_address) return -ENOENT; } -static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, +static int __ffs_func_bind_do_descs(struct ffs_data *ffs, enum ffs_entity_type type, u8 *valuep, struct usb_descriptor_header *desc, void *priv) { @@ -2863,7 +2861,7 @@ static int __ffs_func_bind_do_descs(enum ffs_entity_type type, u8 *valuep, return 0; } -static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, +static int __ffs_func_bind_do_nums(struct ffs_data *ffs, enum ffs_entity_type type, u8 *valuep, struct usb_descriptor_header *desc, void *priv) { @@ -2918,7 +2916,7 @@ static int __ffs_func_bind_do_nums(enum ffs_entity_type type, u8 *valuep, return 0; } -static int __ffs_func_bind_do_os_desc(enum ffs_os_desc_type type, +static int __ffs_func_bind_do_os_desc(struct ffs_data *ffs, enum ffs_os_desc_type type, struct usb_os_desc_header *h, void *data, unsigned len, void *priv) { @@ -3119,7 +3117,7 @@ static int _ffs_func_bind(struct usb_configuration *c, */ if (full) { func->function.fs_descriptors = vla_ptr(vlabuf, d, fs_descs); - fs_len = ffs_do_descs(ffs->fs_descs_count, + fs_len = ffs_do_descs(ffs, ffs->fs_descs_count, vla_ptr(vlabuf, d, raw_descs), d_raw_descs__sz, __ffs_func_bind_do_descs, func); @@ -3133,7 +3131,7 @@ static int _ffs_func_bind(struct usb_configuration *c, if (high) { func->function.hs_descriptors = vla_ptr(vlabuf, d, hs_descs); - hs_len = ffs_do_descs(ffs->hs_descs_count, + hs_len = ffs_do_descs(ffs, ffs->hs_descs_count, vla_ptr(vlabuf, d, raw_descs) + fs_len, d_raw_descs__sz - fs_len, __ffs_func_bind_do_descs, func); @@ -3148,7 +3146,7 @@ static int _ffs_func_bind(struct usb_configuration *c, if (super) { func->function.ss_descriptors = func->function.ssp_descriptors = vla_ptr(vlabuf, d, ss_descs); - ss_len = ffs_do_descs(ffs->ss_descs_count, + ss_len = ffs_do_descs(ffs, ffs->ss_descs_count, vla_ptr(vlabuf, d, raw_descs) + fs_len + hs_len, d_raw_descs__sz - fs_len - hs_len, __ffs_func_bind_do_descs, func); @@ -3165,7 +3163,7 @@ static int _ffs_func_bind(struct usb_configuration *c, * endpoint numbers rewriting. We can do that in one go * now. */ - ret = ffs_do_descs(ffs->fs_descs_count + + ret = ffs_do_descs(ffs, ffs->fs_descs_count + (high ? ffs->hs_descs_count : 0) + (super ? ffs->ss_descs_count : 0), vla_ptr(vlabuf, d, raw_descs), d_raw_descs__sz, @@ -3185,7 +3183,7 @@ static int _ffs_func_bind(struct usb_configuration *c, vla_ptr(vlabuf, d, ext_compat) + i * 16; INIT_LIST_HEAD(&desc->ext_prop); } - ret = ffs_do_os_descs(ffs->ms_os_descs_count, + ret = ffs_do_os_descs(ffs, ffs->ms_os_descs_count, vla_ptr(vlabuf, d, raw_descs) + fs_len + hs_len + ss_len, d_raw_descs__sz - fs_len - hs_len - @@ -3781,7 +3779,7 @@ static int ffs_mutex_lock(struct mutex *mutex, unsigned nonblock) : mutex_lock_interruptible(mutex); } -static char *ffs_prepare_buffer(const char __user *buf, size_t len) +static char *ffs_prepare_buffer(struct ffs_data *ffs, const char __user *buf, size_t len) { char *data; -- 2.7.4