Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

i3c: master: use kzalloc_flex

Simplifies allocations by using a flexible array member in this struct.

Add __counted_by to get extra runtime analysis.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Link: https://patch.msgid.link/20260312001534.24423-1-rosenp@gmail.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

authored by

Rosen Penev and committed by
Alexandre Belloni
7f53c556 eaa1d092

+4 -10
+4 -10
drivers/i3c/master.c
··· 2820 2820 struct i3c_generic_ibi_pool { 2821 2821 spinlock_t lock; 2822 2822 unsigned int num_slots; 2823 - struct i3c_generic_ibi_slot *slots; 2824 2823 void *payload_buf; 2825 2824 struct list_head free_slots; 2826 2825 struct list_head pending; 2826 + struct i3c_generic_ibi_slot slots[] __counted_by(num_slots); 2827 2827 }; 2828 2828 2829 2829 /** ··· 2851 2851 WARN_ON(nslots != pool->num_slots); 2852 2852 2853 2853 kfree(pool->payload_buf); 2854 - kfree(pool->slots); 2855 2854 kfree(pool); 2856 2855 } 2857 2856 EXPORT_SYMBOL_GPL(i3c_generic_ibi_free_pool); ··· 2873 2874 unsigned int i; 2874 2875 int ret; 2875 2876 2876 - pool = kzalloc_obj(*pool); 2877 + pool = kzalloc_flex(*pool, slots, req->num_slots); 2877 2878 if (!pool) 2878 2879 return ERR_PTR(-ENOMEM); 2880 + 2881 + pool->num_slots = req->num_slots; 2879 2882 2880 2883 spin_lock_init(&pool->lock); 2881 2884 INIT_LIST_HEAD(&pool->free_slots); 2882 2885 INIT_LIST_HEAD(&pool->pending); 2883 - 2884 - pool->slots = kzalloc_objs(*slot, req->num_slots); 2885 - if (!pool->slots) { 2886 - ret = -ENOMEM; 2887 - goto err_free_pool; 2888 - } 2889 2886 2890 2887 if (req->max_payload_len) { 2891 2888 pool->payload_buf = kcalloc(req->num_slots, ··· 2901 2906 (i * req->max_payload_len); 2902 2907 2903 2908 list_add_tail(&slot->node, &pool->free_slots); 2904 - pool->num_slots++; 2905 2909 } 2906 2910 2907 2911 return pool;