On 4/26/25 08:23, Kees Cook wrote:
In preparation for making the kmalloc family of allocators type aware,
we need to make sure that the returned type from the allocation matches
the type of the variable being assigned. (Before, the allocator would
always return "void *", which can be implicitly cast to any pointer type.)

The assigned type is "struct dac_info *" but the returned type will be
"struct ics5342_info *", which has a larger allocation size. This is
by design, as struct ics5342_info contains struct dac_info as its first
member. Cast the allocation type to match the assignment.

Signed-off-by: Kees Cook <k...@kernel.org>

Thanks Kees!
I applied your patch, but wouldn't this untested patch be cleaner and fulfill 
the
same purpose to match a kzalloc return type?

diff --git a/drivers/video/fbdev/arkfb.c b/drivers/video/fbdev/arkfb.c
index 7d131e3d159a..a57c8a992e11 100644
--- a/drivers/video/fbdev/arkfb.c
+++ b/drivers/video/fbdev/arkfb.c
@@ -431,7 +431,8 @@ static struct dac_ops ics5342_ops = {
static struct dac_info * ics5342_init(dac_read_regs_t drr, dac_write_regs_t dwr, void *data)
 {
-       struct dac_info *info = (struct dac_info *)kzalloc(sizeof(struct 
ics5342_info), GFP_KERNEL);
+       struct ics5342_info *ics_info = kzalloc(sizeof(struct ics5342_info), 
GFP_KERNEL);
+       struct dac_info *info = &ics_info->dac;
if (! info)


Helge

 ---
Cc: Helge Deller <del...@gmx.de>
Cc: Javier Martinez Canillas <javi...@redhat.com>
Cc: Thomas Zimmermann <tzimmerm...@suse.de>
Cc: Zheyu Ma <zheyum...@gmail.com>
Cc: Samuel Thibault <samuel.thiba...@ens-lyon.org>
Cc: Jiapeng Chong <jiapeng.ch...@linux.alibaba.com>
Cc: <linux-fb...@vger.kernel.org>
Cc: <dri-devel@lists.freedesktop.org>
---
  drivers/video/fbdev/arkfb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/arkfb.c b/drivers/video/fbdev/arkfb.c
index 082501feceb9..7d131e3d159a 100644
--- a/drivers/video/fbdev/arkfb.c
+++ b/drivers/video/fbdev/arkfb.c
@@ -431,7 +431,7 @@ static struct dac_ops ics5342_ops = {
static struct dac_info * ics5342_init(dac_read_regs_t drr, dac_write_regs_t dwr, void *data)
  {
-       struct dac_info *info = kzalloc(sizeof(struct ics5342_info), 
GFP_KERNEL);
+       struct dac_info *info = (struct dac_info *)kzalloc(sizeof(struct 
ics5342_info), GFP_KERNEL);
if (! info)
                return NULL;

Reply via email to