diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/usb/gadget/function | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:
Single allocations: kmalloc(sizeof(TYPE), ...)
are replaced with: kmalloc_obj(TYPE, ...)
Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with: kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
(where TYPE may also be *VAR)
The resulting allocations no longer return "void *", instead returning
"TYPE *".
Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'drivers/usb/gadget/function')
29 files changed, 101 insertions, 104 deletions
diff --git a/drivers/usb/gadget/function/f_acm.c b/drivers/usb/gadget/function/f_acm.c index 0ad857f1f325..d34b4710f962 100644 --- a/drivers/usb/gadget/function/f_acm.c +++ b/drivers/usb/gadget/function/f_acm.c @@ -748,7 +748,7 @@ static struct usb_function *acm_alloc_func(struct usb_function_instance *fi) struct f_serial_opts *opts; struct f_acm *acm; - acm = kzalloc(sizeof(*acm), GFP_KERNEL); + acm = kzalloc_obj(*acm, GFP_KERNEL); if (!acm) return ERR_PTR(-ENOMEM); @@ -882,7 +882,7 @@ static struct usb_function_instance *acm_alloc_instance(void) struct f_serial_opts *opts; int ret; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); opts->protocol = USB_CDC_ACM_PROTO_AT_V25TER; diff --git a/drivers/usb/gadget/function/f_ecm.c b/drivers/usb/gadget/function/f_ecm.c index 675d2bc538a4..aa91d705bc8d 100644 --- a/drivers/usb/gadget/function/f_ecm.c +++ b/drivers/usb/gadget/function/f_ecm.c @@ -847,7 +847,7 @@ static struct usb_function_instance *ecm_alloc_inst(void) { struct f_ecm_opts *opts; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); mutex_init(&opts->lock); @@ -927,7 +927,7 @@ static struct usb_function *ecm_alloc(struct usb_function_instance *fi) int status; /* allocate and initialize one new instance */ - ecm = kzalloc(sizeof(*ecm), GFP_KERNEL); + ecm = kzalloc_obj(*ecm, GFP_KERNEL); if (!ecm) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_eem.c b/drivers/usb/gadget/function/f_eem.c index edbbadad6138..acdd6c637c7b 100644 --- a/drivers/usb/gadget/function/f_eem.c +++ b/drivers/usb/gadget/function/f_eem.c @@ -462,7 +462,7 @@ static int eem_unwrap(struct gether *port, goto next; } - ctx = kmalloc(sizeof(*ctx), GFP_KERNEL); + ctx = kmalloc_obj(*ctx, GFP_KERNEL); if (!ctx) { kfree(req->buf); usb_ep_free_request(ep, req); @@ -608,7 +608,7 @@ static struct usb_function_instance *eem_alloc_inst(void) { struct f_eem_opts *opts; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); mutex_init(&opts->lock); @@ -651,7 +651,7 @@ static struct usb_function *eem_alloc(struct usb_function_instance *fi) struct f_eem_opts *opts; /* allocate and initialize one new instance */ - eem = kzalloc(sizeof(*eem), GFP_KERNEL); + eem = kzalloc_obj(*eem, GFP_KERNEL); if (!eem) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c index 2c6986e381ca..84cfa7a8437a 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -814,7 +814,7 @@ static void *ffs_build_sg_list(struct sg_table *sgt, size_t sz) return NULL; n_pages = PAGE_ALIGN(sz) >> PAGE_SHIFT; - pages = kvmalloc_array(n_pages, sizeof(struct page *), GFP_KERNEL); + pages = kvmalloc_objs(struct page *, n_pages, GFP_KERNEL); if (!pages) { vfree(vaddr); @@ -957,7 +957,7 @@ static ssize_t __ffs_epfile_read_data(struct ffs_epfile *epfile, data_len, ret); data_len -= ret; - buf = kmalloc(struct_size(buf, storage, data_len), GFP_KERNEL); + buf = kmalloc_flex(*buf, storage, data_len, GFP_KERNEL); if (!buf) return -ENOMEM; buf->length = data_len; @@ -1245,7 +1245,7 @@ static ssize_t ffs_epfile_write_iter(struct kiocb *kiocb, struct iov_iter *from) ssize_t res; if (!is_sync_kiocb(kiocb)) { - p = kzalloc(sizeof(io_data), GFP_KERNEL); + p = kzalloc_obj(io_data, GFP_KERNEL); if (!p) return -ENOMEM; p->aio = true; @@ -1280,7 +1280,7 @@ static ssize_t ffs_epfile_read_iter(struct kiocb *kiocb, struct iov_iter *to) ssize_t res; if (!is_sync_kiocb(kiocb)) { - p = kzalloc(sizeof(io_data), GFP_KERNEL); + p = kzalloc_obj(io_data, GFP_KERNEL); if (!p) return -ENOMEM; p->aio = true; @@ -1503,7 +1503,7 @@ static int ffs_dmabuf_attach(struct file *file, int fd) goto err_dmabuf_put; } - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = kzalloc_obj(*priv, GFP_KERNEL); if (!priv) { err = -ENOMEM; goto err_dmabuf_detach; @@ -1652,7 +1652,7 @@ static int ffs_dmabuf_transfer(struct file *file, if (ret) goto err_resv_unlock; - fence = kmalloc(sizeof(*fence), GFP_KERNEL); + fence = kmalloc_obj(*fence, GFP_KERNEL); if (!fence) { ret = -ENOMEM; goto err_resv_unlock; @@ -2067,7 +2067,7 @@ static int ffs_fs_init_fs_context(struct fs_context *fc) { struct ffs_sb_fill_data *ctx; - ctx = kzalloc(sizeof(struct ffs_sb_fill_data), GFP_KERNEL); + ctx = kzalloc_obj(struct ffs_sb_fill_data, GFP_KERNEL); if (!ctx) return -ENOMEM; @@ -2183,7 +2183,7 @@ static void ffs_data_closed(struct ffs_data *ffs) static struct ffs_data *ffs_data_new(const char *dev_name) { - struct ffs_data *ffs = kzalloc(sizeof *ffs, GFP_KERNEL); + struct ffs_data *ffs = kzalloc_obj(*ffs, GFP_KERNEL); if (!ffs) return NULL; @@ -2330,7 +2330,7 @@ static int ffs_epfiles_create(struct ffs_data *ffs) int err; count = ffs->eps_count; - epfiles = kcalloc(count, sizeof(*epfiles), GFP_KERNEL); + epfiles = kzalloc_objs(*epfiles, count, GFP_KERNEL); if (!epfiles) return -ENOMEM; @@ -4031,7 +4031,7 @@ static struct usb_function_instance *ffs_alloc_inst(void) struct f_fs_opts *opts; struct ffs_dev *dev; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); @@ -4107,7 +4107,7 @@ static struct usb_function *ffs_alloc(struct usb_function_instance *fi) { struct ffs_function *func; - func = kzalloc(sizeof(*func), GFP_KERNEL); + func = kzalloc_obj(*func, GFP_KERNEL); if (!func) return ERR_PTR(-ENOMEM); @@ -4138,7 +4138,7 @@ static struct ffs_dev *_ffs_alloc_dev(void) if (_ffs_get_single_dev()) return ERR_PTR(-EBUSY); - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = kzalloc_obj(*dev, GFP_KERNEL); if (!dev) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c index bee0d0458ff7..93dd678cafe1 100644 --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c @@ -650,7 +650,7 @@ static int f_hidg_get_report(struct file *file, struct usb_hidg_report __user *b struct report_entry *ptr; __u8 report_id; - entry = kmalloc(sizeof(*entry), GFP_KERNEL); + entry = kmalloc_obj(*entry, GFP_KERNEL); if (!entry) return -ENOMEM; @@ -775,7 +775,7 @@ static void hidg_intout_complete(struct usb_ep *ep, struct usb_request *req) switch (req->status) { case 0: - req_list = kzalloc(sizeof(*req_list), GFP_ATOMIC); + req_list = kzalloc_obj(*req_list, GFP_ATOMIC); if (!req_list) { ERROR(cdev, "Unable to allocate mem for req_list\n"); goto free_req; @@ -1530,7 +1530,7 @@ static struct usb_function_instance *hidg_alloc_inst(void) struct usb_function_instance *ret; int status = 0; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); mutex_init(&opts->lock); @@ -1596,7 +1596,7 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi) int ret; /* allocate and initialize one new instance */ - hidg = kzalloc(sizeof(*hidg), GFP_KERNEL); + hidg = kzalloc_obj(*hidg, GFP_KERNEL); if (!hidg) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_loopback.c b/drivers/usb/gadget/function/f_loopback.c index 39862e236837..b8fa60af9385 100644 --- a/drivers/usb/gadget/function/f_loopback.c +++ b/drivers/usb/gadget/function/f_loopback.c @@ -425,7 +425,7 @@ static struct usb_function *loopback_alloc(struct usb_function_instance *fi) struct f_loopback *loop; struct f_lb_opts *lb_opts; - loop = kzalloc(sizeof *loop, GFP_KERNEL); + loop = kzalloc_obj(*loop, GFP_KERNEL); if (!loop) return ERR_PTR(-ENOMEM); @@ -568,7 +568,7 @@ static struct usb_function_instance *loopback_alloc_instance(void) { struct f_lb_opts *lb_opts; - lb_opts = kzalloc(sizeof(*lb_opts), GFP_KERNEL); + lb_opts = kzalloc_obj(*lb_opts, GFP_KERNEL); if (!lb_opts) return ERR_PTR(-ENOMEM); mutex_init(&lb_opts->lock); diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c index 5c3f34a2f35c..c894ede6bcd2 100644 --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -2699,7 +2699,7 @@ static void fsg_lun_release(struct device *dev) static struct fsg_common *fsg_common_setup(struct fsg_common *common) { if (!common) { - common = kzalloc(sizeof(*common), GFP_KERNEL); + common = kzalloc_obj(*common, GFP_KERNEL); if (!common) return ERR_PTR(-ENOMEM); common->free_storage_on_release = 1; @@ -2740,7 +2740,7 @@ int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n) struct fsg_buffhd *bh, *buffhds; int i; - buffhds = kcalloc(n, sizeof(*buffhds), GFP_KERNEL); + buffhds = kzalloc_objs(*buffhds, n, GFP_KERNEL); if (!buffhds) return -ENOMEM; @@ -2887,7 +2887,7 @@ int fsg_common_create_lun(struct fsg_common *common, struct fsg_lun_config *cfg, return -EINVAL; } - lun = kzalloc(sizeof(*lun), GFP_KERNEL); + lun = kzalloc_obj(*lun, GFP_KERNEL); if (!lun) return -ENOMEM; @@ -3311,7 +3311,7 @@ static struct config_group *fsg_lun_make(struct config_group *group, goto out; } - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) { ret = -ENOMEM; goto out; @@ -3489,7 +3489,7 @@ static struct usb_function_instance *fsg_alloc_inst(void) struct fsg_lun_config config; int rc; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); mutex_init(&opts->lock); @@ -3554,7 +3554,7 @@ static struct usb_function *fsg_alloc(struct usb_function_instance *fi) struct fsg_common *common = opts->common; struct fsg_dev *fsg; - fsg = kzalloc(sizeof(*fsg), GFP_KERNEL); + fsg = kzalloc_obj(*fsg, GFP_KERNEL); if (unlikely(!fsg)) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c index f592f9eb85d4..d98f946b1621 100644 --- a/drivers/usb/gadget/function/f_midi.c +++ b/drivers/usb/gadget/function/f_midi.c @@ -931,8 +931,8 @@ static int f_midi_bind(struct usb_configuration *c, struct usb_function *f) goto fail; /* allocate temporary function list */ - midi_function = kcalloc((MAX_PORTS * 4) + 11, sizeof(*midi_function), - GFP_KERNEL); + midi_function = kzalloc_objs(*midi_function, (MAX_PORTS * 4) + 11, + GFP_KERNEL); if (!midi_function) { status = -ENOMEM; goto fail; @@ -1279,7 +1279,7 @@ static struct usb_function_instance *f_midi_alloc_inst(void) { struct f_midi_opts *opts; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); @@ -1361,8 +1361,7 @@ static struct usb_function *f_midi_alloc(struct usb_function_instance *fi) } /* allocate and initialize one new instance */ - midi = kzalloc(struct_size(midi, in_ports_array, opts->in_ports), - GFP_KERNEL); + midi = kzalloc_flex(*midi, in_ports_array, opts->in_ports, GFP_KERNEL); if (!midi) { status = -ENOMEM; goto setup_fail; diff --git a/drivers/usb/gadget/function/f_midi2.c b/drivers/usb/gadget/function/f_midi2.c index 95ec87bed3ee..1a4feca1f083 100644 --- a/drivers/usb/gadget/function/f_midi2.c +++ b/drivers/usb/gadget/function/f_midi2.c @@ -1187,8 +1187,8 @@ static int f_midi2_init_ep(struct f_midi2 *midi2, struct f_midi2_ep *ep, return -ENODEV; usb_ep->complete = complete; - usb_ep->reqs = kcalloc(midi2->info.num_reqs, sizeof(*usb_ep->reqs), - GFP_KERNEL); + usb_ep->reqs = kzalloc_objs(*usb_ep->reqs, midi2->info.num_reqs, + GFP_KERNEL); if (!usb_ep->reqs) return -ENOMEM; for (i = 0; i < midi2->info.num_reqs; i++) { @@ -2340,7 +2340,7 @@ static int f_midi2_block_opts_create(struct f_midi2_ep_opts *ep_opts, goto out; } - block_opts = kzalloc(sizeof(*block_opts), GFP_KERNEL); + block_opts = kzalloc_obj(*block_opts, GFP_KERNEL); if (!block_opts) { ret = -ENOMEM; goto out; @@ -2502,7 +2502,7 @@ static int f_midi2_ep_opts_create(struct f_midi2_opts *opts, { struct f_midi2_ep_opts *ep_opts; - ep_opts = kzalloc(sizeof(*ep_opts), GFP_KERNEL); + ep_opts = kzalloc_obj(*ep_opts, GFP_KERNEL); if (!ep_opts) return -ENOMEM; @@ -2652,7 +2652,7 @@ static struct usb_function_instance *f_midi2_alloc_inst(void) struct f_midi2_block_opts *block_opts; int ret; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); @@ -2813,7 +2813,7 @@ static struct usb_function *f_midi2_alloc(struct usb_function_instance *fi) struct f_midi2_block *bp; int i, num_eps, blk; - midi2 = kzalloc(sizeof(*midi2), GFP_KERNEL); + midi2 = kzalloc_obj(*midi2, GFP_KERNEL); if (!midi2) return ERR_PTR(-ENOMEM); @@ -2855,8 +2855,8 @@ static struct usb_function *f_midi2_alloc(struct usb_function_instance *fi) } } - midi2->string_defs = kcalloc(midi2->total_blocks + 1, - sizeof(*midi2->string_defs), GFP_KERNEL); + midi2->string_defs = kzalloc_objs(*midi2->string_defs, + midi2->total_blocks + 1, GFP_KERNEL); if (!midi2->string_defs) { do_f_midi2_free(midi2, opts); return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c index e23adc132f88..6bbdb10ce3ca 100644 --- a/drivers/usb/gadget/function/f_ncm.c +++ b/drivers/usb/gadget/function/f_ncm.c @@ -1683,7 +1683,7 @@ static struct usb_function_instance *ncm_alloc_inst(void) char *names[1]; struct config_group *ncm_interf_group; - struct f_ncm_opts *opts __free(kfree) = kzalloc(sizeof(*opts), GFP_KERNEL); + struct f_ncm_opts *opts __free(kfree) = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_obex.c b/drivers/usb/gadget/function/f_obex.c index 6d498f63183e..e9e9fd70c243 100644 --- a/drivers/usb/gadget/function/f_obex.c +++ b/drivers/usb/gadget/function/f_obex.c @@ -426,7 +426,7 @@ static struct usb_function_instance *obex_alloc_inst(void) struct f_serial_opts *opts; int ret; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); @@ -461,7 +461,7 @@ static struct usb_function *obex_alloc(struct usb_function_instance *fi) struct f_serial_opts *opts; /* allocate and initialize one new instance */ - obex = kzalloc(sizeof(*obex), GFP_KERNEL); + obex = kzalloc_obj(*obex, GFP_KERNEL); if (!obex) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_phonet.c b/drivers/usb/gadget/function/f_phonet.c index d644d5495fdc..b427dcae456c 100644 --- a/drivers/usb/gadget/function/f_phonet.c +++ b/drivers/usb/gadget/function/f_phonet.c @@ -623,7 +623,7 @@ static struct usb_function_instance *phonet_alloc_inst(void) { struct f_phonet_opts *opts; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); @@ -669,7 +669,7 @@ static struct usb_function *phonet_alloc(struct usb_function_instance *fi) struct f_phonet *fp; struct f_phonet_opts *opts; - fp = kzalloc(struct_size(fp, out_reqv, phonet_rxq_size), GFP_KERNEL); + fp = kzalloc_flex(*fp, out_reqv, phonet_rxq_size, GFP_KERNEL); if (!fp) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c index b2fa2b56c37e..d0e6435ac7a6 100644 --- a/drivers/usb/gadget/function/f_printer.c +++ b/drivers/usb/gadget/function/f_printer.c @@ -1374,7 +1374,7 @@ static struct usb_function_instance *gprinter_alloc_inst(void) struct usb_function_instance *ret; int status = 0; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); @@ -1482,7 +1482,7 @@ static struct usb_function *gprinter_alloc(struct usb_function_instance *fi) return ERR_PTR(-ENOENT); } - dev = kzalloc(sizeof(*dev), GFP_KERNEL); + dev = kzalloc_obj(*dev, GFP_KERNEL); if (!dev) { mutex_unlock(&opts->lock); return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_rndis.c b/drivers/usb/gadget/function/f_rndis.c index 7451e7cb7a85..39a87458bab4 100644 --- a/drivers/usb/gadget/function/f_rndis.c +++ b/drivers/usb/gadget/function/f_rndis.c @@ -673,7 +673,7 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f) rndis_opts = container_of(f->fi, struct f_rndis_opts, func_inst); if (cdev->use_os_string) { - os_desc_table = kzalloc(sizeof(*os_desc_table), GFP_KERNEL); + os_desc_table = kzalloc_obj(*os_desc_table, GFP_KERNEL); if (!os_desc_table) return -ENOMEM; } @@ -888,7 +888,7 @@ static struct usb_function_instance *rndis_alloc_inst(void) char *names[1]; struct config_group *rndis_interf_group; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); opts->rndis_os_desc.ext_compat_id = opts->rndis_ext_compat_id; @@ -956,7 +956,7 @@ static struct usb_function *rndis_alloc(struct usb_function_instance *fi) struct rndis_params *params; /* allocate and initialize one new instance */ - rndis = kzalloc(sizeof(*rndis), GFP_KERNEL); + rndis = kzalloc_obj(*rndis, GFP_KERNEL); if (!rndis) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_serial.c b/drivers/usb/gadget/function/f_serial.c index e6b412e0e045..01fc06b29ab2 100644 --- a/drivers/usb/gadget/function/f_serial.c +++ b/drivers/usb/gadget/function/f_serial.c @@ -317,7 +317,7 @@ static struct usb_function_instance *gser_alloc_inst(void) struct f_serial_opts *opts; int ret; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); @@ -376,7 +376,7 @@ static struct usb_function *gser_alloc(struct usb_function_instance *fi) struct f_serial_opts *opts; /* allocate and initialize one new instance */ - gser = kzalloc(sizeof(*gser), GFP_KERNEL); + gser = kzalloc_obj(*gser, GFP_KERNEL); if (!gser) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c index 22104e9c6cab..e77e2e83833f 100644 --- a/drivers/usb/gadget/function/f_sourcesink.c +++ b/drivers/usb/gadget/function/f_sourcesink.c @@ -844,7 +844,7 @@ static struct usb_function *source_sink_alloc_func( struct f_sourcesink *ss; struct f_ss_opts *ss_opts; - ss = kzalloc(sizeof(*ss), GFP_KERNEL); + ss = kzalloc_obj(*ss, GFP_KERNEL); if (!ss) return ERR_PTR(-ENOMEM); @@ -1297,7 +1297,7 @@ static struct usb_function_instance *source_sink_alloc_inst(void) { struct f_ss_opts *ss_opts; - ss_opts = kzalloc(sizeof(*ss_opts), GFP_KERNEL); + ss_opts = kzalloc_obj(*ss_opts, GFP_KERNEL); if (!ss_opts) return ERR_PTR(-ENOMEM); mutex_init(&ss_opts->lock); diff --git a/drivers/usb/gadget/function/f_subset.c b/drivers/usb/gadget/function/f_subset.c index ea3fdd842462..4913f60db048 100644 --- a/drivers/usb/gadget/function/f_subset.c +++ b/drivers/usb/gadget/function/f_subset.c @@ -428,7 +428,7 @@ static struct usb_function_instance *geth_alloc_inst(void) { struct f_gether_opts *opts; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); mutex_init(&opts->lock); @@ -467,7 +467,7 @@ static struct usb_function *geth_alloc(struct usb_function_instance *fi) int status; /* allocate and initialize one new instance */ - geth = kzalloc(sizeof(*geth), GFP_KERNEL); + geth = kzalloc_obj(*geth, GFP_KERNEL); if (!geth) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index efb94fd82533..29d6fd6ce935 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c @@ -1676,7 +1676,7 @@ static struct se_portal_group *usbg_make_tpg(struct se_wwn *wwn, goto unlock_dep; } - tpg = kzalloc(sizeof(struct usbg_tpg), GFP_KERNEL); + tpg = kzalloc_obj(struct usbg_tpg, GFP_KERNEL); ret = -ENOMEM; if (!tpg) goto unref_dep; @@ -1768,7 +1768,7 @@ static struct se_wwn *usbg_make_tport( if (!wnn_name) return ERR_PTR(-EINVAL); - tport = kzalloc(sizeof(struct usbg_tport), GFP_KERNEL); + tport = kzalloc_obj(struct usbg_tport, GFP_KERNEL); if (!(tport)) return ERR_PTR(-ENOMEM); @@ -1861,7 +1861,7 @@ static int tcm_usbg_make_nexus(struct usbg_tpg *tpg, char *name) goto out_unlock; } - tv_nexus = kzalloc(sizeof(*tv_nexus), GFP_KERNEL); + tv_nexus = kzalloc_obj(*tv_nexus, GFP_KERNEL); if (!tv_nexus) { ret = -ENOMEM; goto out_unlock; @@ -2400,7 +2400,7 @@ static int tcm_set_alt(struct usb_function *f, unsigned intf, unsigned alt) if ((alt == USB_G_ALT_INT_BBB) || (alt == USB_G_ALT_INT_UAS)) { struct guas_setup_wq *work; - work = kmalloc(sizeof(*work), GFP_ATOMIC); + work = kmalloc_obj(*work, GFP_ATOMIC); if (!work) return -ENOMEM; INIT_WORK(&work->work, tcm_delayed_set_alt); @@ -2535,7 +2535,7 @@ static struct usb_function_instance *tcm_alloc_inst(void) int i; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); @@ -2590,7 +2590,7 @@ static struct usb_function *tcm_alloc(struct usb_function_instance *fi) return ERR_PTR(-ENODEV); } - fu = kzalloc(sizeof(*fu), GFP_KERNEL); + fu = kzalloc_obj(*fu, GFP_KERNEL); if (!fu) { mutex_unlock(&tpg_instances_lock); return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c index efe9f270b02d..58ada4855de8 100644 --- a/drivers/usb/gadget/function/f_uac1.c +++ b/drivers/usb/gadget/function/f_uac1.c @@ -451,7 +451,7 @@ static int audio_notify(struct g_audio *audio, int unit_id, int cs) goto err_dec_int_count; } - msg = kmalloc(sizeof(*msg), GFP_ATOMIC); + msg = kmalloc_obj(*msg, GFP_ATOMIC); if (msg == NULL) { ret = -ENOMEM; goto err_free_request; @@ -1748,7 +1748,7 @@ static struct usb_function_instance *f_audio_alloc_inst(void) { struct f_uac1_opts *opts; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); @@ -1831,7 +1831,7 @@ static struct usb_function *f_audio_alloc(struct usb_function_instance *fi) struct f_uac1_opts *opts; /* allocate and initialize one new instance */ - uac1 = kzalloc(sizeof(*uac1), GFP_KERNEL); + uac1 = kzalloc_obj(*uac1, GFP_KERNEL); if (!uac1) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_uac1_legacy.c b/drivers/usb/gadget/function/f_uac1_legacy.c index 8fc452b4b39a..ed7e1f061784 100644 --- a/drivers/usb/gadget/function/f_uac1_legacy.c +++ b/drivers/usb/gadget/function/f_uac1_legacy.c @@ -251,7 +251,7 @@ static struct f_audio_buf *f_audio_buffer_alloc(int buf_size) { struct f_audio_buf *copy_buf; - copy_buf = kzalloc(sizeof *copy_buf, GFP_ATOMIC); + copy_buf = kzalloc_obj(*copy_buf, GFP_ATOMIC); if (!copy_buf) return ERR_PTR(-ENOMEM); @@ -942,7 +942,7 @@ static struct usb_function_instance *f_audio_alloc_inst(void) { struct f_uac1_legacy_opts *opts; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); @@ -985,7 +985,7 @@ static struct usb_function *f_audio_alloc(struct usb_function_instance *fi) struct f_uac1_legacy_opts *opts; /* allocate and initialize one new instance */ - audio = kzalloc(sizeof(*audio), GFP_KERNEL); + audio = kzalloc_obj(*audio, GFP_KERNEL); if (!audio) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c index 98f0f50dc7a8..c66908bbe714 100644 --- a/drivers/usb/gadget/function/f_uac2.c +++ b/drivers/usb/gadget/function/f_uac2.c @@ -1388,7 +1388,7 @@ afunc_notify(struct g_audio *agdev, int unit_id, int cs) goto err_dec_int_count; } - msg = kzalloc(sizeof(*msg), GFP_ATOMIC); + msg = kzalloc_obj(*msg, GFP_ATOMIC); if (msg == NULL) { ret = -ENOMEM; goto err_free_request; @@ -2189,7 +2189,7 @@ static struct usb_function_instance *afunc_alloc_inst(void) { struct f_uac2_opts *opts; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); @@ -2278,7 +2278,7 @@ static struct usb_function *afunc_alloc(struct usb_function_instance *fi) struct f_uac2 *uac2; struct f_uac2_opts *opts; - uac2 = kzalloc(sizeof(*uac2), GFP_KERNEL); + uac2 = kzalloc_obj(*uac2, GFP_KERNEL); if (uac2 == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/f_uvc.c b/drivers/usb/gadget/function/f_uvc.c index a96476507d2f..4b9846ab99f2 100644 --- a/drivers/usb/gadget/function/f_uvc.c +++ b/drivers/usb/gadget/function/f_uvc.c @@ -887,7 +887,7 @@ static struct usb_function_instance *uvc_alloc_inst(void) struct uvc_descriptor_header **ctl_cls; int ret; - opts = kzalloc(sizeof(*opts), GFP_KERNEL); + opts = kzalloc_obj(*opts, GFP_KERNEL); if (!opts) return ERR_PTR(-ENOMEM); opts->func_inst.free_func_inst = uvc_free_inst; @@ -1042,7 +1042,7 @@ static struct usb_function *uvc_alloc(struct usb_function_instance *fi) struct uvc_descriptor_header **strm_cls; struct config_item *streaming, *header, *h; - uvc = kzalloc(sizeof(*uvc), GFP_KERNEL); + uvc = kzalloc_obj(*uvc, GFP_KERNEL); if (uvc == NULL) return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/rndis.c b/drivers/usb/gadget/function/rndis.c index afd75d72412c..1e168666a3f5 100644 --- a/drivers/usb/gadget/function/rndis.c +++ b/drivers/usb/gadget/function/rndis.c @@ -892,7 +892,7 @@ struct rndis_params *rndis_register(void (*resp_avail)(void *v), void *v) return ERR_PTR(-ENODEV); } - params = kzalloc(sizeof(*params), GFP_KERNEL); + params = kzalloc_obj(*params, GFP_KERNEL); if (!params) { rndis_put_nr(i); diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index ca8dbec65f73..24c934bbf0e5 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -1191,7 +1191,7 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, if (!g_audio) return -EINVAL; - uac = kzalloc(sizeof(*uac), GFP_KERNEL); + uac = kzalloc_obj(*uac, GFP_KERNEL); if (!uac) return -ENOMEM; g_audio->uac = uac; @@ -1209,9 +1209,8 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, prm->max_psize = g_audio->out_ep_maxpsize; prm->srate = params->c_srates[0]; - prm->reqs = kcalloc(params->req_number, - sizeof(struct usb_request *), - GFP_KERNEL); + prm->reqs = kzalloc_objs(struct usb_request *, + params->req_number, GFP_KERNEL); if (!prm->reqs) { err = -ENOMEM; goto fail; @@ -1234,9 +1233,8 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, prm->max_psize = g_audio->in_ep_maxpsize; prm->srate = params->p_srates[0]; - prm->reqs = kcalloc(params->req_number, - sizeof(struct usb_request *), - GFP_KERNEL); + prm->reqs = kzalloc_objs(struct usb_request *, + params->req_number, GFP_KERNEL); if (!prm->reqs) { err = -ENOMEM; goto fail; diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index 1cce5317181a..e61beaa0c53d 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -1082,7 +1082,7 @@ static int gs_console_init(struct gs_port *port) if (port->console) return 0; - cons = kzalloc(sizeof(*port->console), GFP_KERNEL); + cons = kzalloc_obj(*port->console, GFP_KERNEL); if (!cons) return -ENOMEM; @@ -1215,7 +1215,7 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) goto out; } - port = kzalloc(sizeof(struct gs_port), GFP_KERNEL); + port = kzalloc_obj(struct gs_port, GFP_KERNEL); if (port == NULL) { ret = -ENOMEM; goto out; diff --git a/drivers/usb/gadget/function/u_uac1_legacy.c b/drivers/usb/gadget/function/u_uac1_legacy.c index dd21c251542c..e95c2fc7fc10 100644 --- a/drivers/usb/gadget/function/u_uac1_legacy.c +++ b/drivers/usb/gadget/function/u_uac1_legacy.c @@ -106,7 +106,7 @@ static int playback_default_hw_params(struct gaudio_snd_dev *snd) snd->channels = 2; snd->rate = 48000; - params = kzalloc(sizeof(*params), GFP_KERNEL); + params = kzalloc_obj(*params, GFP_KERNEL); if (!params) return -ENOMEM; diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c index 4cec6c586d67..553057cbf63a 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -158,7 +158,7 @@ static int uvcg_config_create_group(struct config_group *parent, { struct config_group *group; - group = kzalloc(sizeof(*group), GFP_KERNEL); + group = kzalloc_obj(*group, GFP_KERNEL); if (!group) return -ENOMEM; @@ -270,7 +270,7 @@ static struct config_item *uvcg_control_header_make(struct config_group *group, { struct uvcg_control_header *h; - h = kzalloc(sizeof(*h), GFP_KERNEL); + h = kzalloc_obj(*h, GFP_KERNEL); if (!h) return ERR_PTR(-ENOMEM); @@ -1273,7 +1273,7 @@ static struct config_item *uvcg_extension_make(struct config_group *group, const opts_item = group->cg_item.ci_parent->ci_parent; opts = to_f_uvc_opts(opts_item); - xu = kzalloc(sizeof(*xu), GFP_KERNEL); + xu = kzalloc_obj(*xu, GFP_KERNEL); if (!xu) return ERR_PTR(-ENOMEM); @@ -1437,7 +1437,7 @@ static int uvcg_control_class_create_children(struct config_group *parent) for (i = 0; i < ARRAY_SIZE(names); ++i) { struct uvcg_control_class_group *group; - group = kzalloc(sizeof(*group), GFP_KERNEL); + group = kzalloc_obj(*group, GFP_KERNEL); if (!group) return -ENOMEM; @@ -1785,7 +1785,7 @@ static int uvcg_streaming_header_allow_link(struct config_item *src, uvcg_format_set_indices(to_config_group(target)); - format_ptr = kzalloc(sizeof(*format_ptr), GFP_KERNEL); + format_ptr = kzalloc_obj(*format_ptr, GFP_KERNEL); if (!format_ptr) { ret = -ENOMEM; goto out; @@ -1899,7 +1899,7 @@ static struct config_item { struct uvcg_streaming_header *h; - h = kzalloc(sizeof(*h), GFP_KERNEL); + h = kzalloc_obj(*h, GFP_KERNEL); if (!h) return ERR_PTR(-ENOMEM); @@ -2163,7 +2163,7 @@ static struct config_item *uvcg_frame_make(struct config_group *group, struct config_item *opts_item; struct uvcg_frame_ptr *frame_ptr; - h = kzalloc(sizeof(*h), GFP_KERNEL); + h = kzalloc_obj(*h, GFP_KERNEL); if (!h) return ERR_PTR(-ENOMEM); @@ -2197,7 +2197,7 @@ static struct config_item *uvcg_frame_make(struct config_group *group, return ERR_PTR(-EINVAL); } - frame_ptr = kzalloc(sizeof(*frame_ptr), GFP_KERNEL); + frame_ptr = kzalloc_obj(*frame_ptr, GFP_KERNEL); if (!frame_ptr) { mutex_unlock(&opts->lock); kfree(h); @@ -2483,7 +2483,7 @@ static struct config_group *uvcg_uncompressed_make(struct config_group *group, if (!color_match) return ERR_PTR(-EINVAL); - h = kzalloc(sizeof(*h), GFP_KERNEL); + h = kzalloc_obj(*h, GFP_KERNEL); if (!h) return ERR_PTR(-ENOMEM); @@ -2675,7 +2675,7 @@ static struct config_group *uvcg_mjpeg_make(struct config_group *group, if (!color_match) return ERR_PTR(-EINVAL); - h = kzalloc(sizeof(*h), GFP_KERNEL); + h = kzalloc_obj(*h, GFP_KERNEL); if (!h) return ERR_PTR(-ENOMEM); @@ -2926,7 +2926,7 @@ static struct config_group *uvcg_framebased_make(struct config_group *group, if (!color_match) return ERR_PTR(-EINVAL); - h = kzalloc(sizeof(*h), GFP_KERNEL); + h = kzalloc_obj(*h, GFP_KERNEL); if (!h) return ERR_PTR(-ENOMEM); @@ -3075,7 +3075,7 @@ static struct config_group *uvcg_color_matching_make(struct config_group *group, { struct uvcg_color_matching *color_match; - color_match = kzalloc(sizeof(*color_match), GFP_KERNEL); + color_match = kzalloc_obj(*color_match, GFP_KERNEL); if (!color_match) return ERR_PTR(-ENOMEM); @@ -3097,7 +3097,7 @@ static int uvcg_color_matching_create_children(struct config_group *parent) { struct uvcg_color_matching *color_match; - color_match = kzalloc(sizeof(*color_match), GFP_KERNEL); + color_match = kzalloc_obj(*color_match, GFP_KERNEL); if (!color_match) return -ENOMEM; @@ -3553,7 +3553,7 @@ static int uvcg_streaming_class_create_children(struct config_group *parent) for (i = 0; i < ARRAY_SIZE(names); ++i) { struct uvcg_streaming_class_group *group; - group = kzalloc(sizeof(*group), GFP_KERNEL); + group = kzalloc_obj(*group, GFP_KERNEL); if (!group) return -ENOMEM; diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/function/uvc_v4l2.c index fd4b998ccd16..574b3a8986a0 100644 --- a/drivers/usb/gadget/function/uvc_v4l2.c +++ b/drivers/usb/gadget/function/uvc_v4l2.c @@ -667,7 +667,7 @@ uvc_v4l2_open(struct file *file) struct uvc_device *uvc = video_get_drvdata(vdev); struct uvc_file_handle *handle; - handle = kzalloc(sizeof(*handle), GFP_KERNEL); + handle = kzalloc_obj(*handle, GFP_KERNEL); if (handle == NULL) return -ENOMEM; diff --git a/drivers/usb/gadget/function/uvc_video.c b/drivers/usb/gadget/function/uvc_video.c index f568dee08b3b..b2784a57dbcd 100644 --- a/drivers/usb/gadget/function/uvc_video.c +++ b/drivers/usb/gadget/function/uvc_video.c @@ -559,7 +559,7 @@ uvc_video_alloc_requests(struct uvc_video *video) uvc_video_prep_requests(video); for (i = 0; i < video->uvc_num_requests; i++) { - ureq = kzalloc(sizeof(struct uvc_request), GFP_KERNEL); + ureq = kzalloc_obj(struct uvc_request, GFP_KERNEL); if (ureq == NULL) goto error; |
