All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drivers/firewire: use struct_size over open coded arithmetic
@ 2022-01-28  8:03 cgel.zte
  2022-01-28 12:08   ` kernel test robot
  2022-01-28 14:54   ` kernel test robot
  0 siblings, 2 replies; 5+ messages in thread
From: cgel.zte @ 2022-01-28  8:03 UTC (permalink / raw)
  To: stefanr; +Cc: linux1394-devel, linux-kernel, Minghao Chi, Zeal Robot

From: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>

Replace zero-length array with flexible-array member and make use
of the struct_size() helper in kmalloc(). For example:

struct fw_request {
	...
	u32 data[];
}

Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Minghao Chi (CGEL ZTE) <chi.minghao@zte.com.cn>
---
 drivers/firewire/core-transaction.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
index ac487c96bb71..2e9dd988ed0e 100644
--- a/drivers/firewire/core-transaction.c
+++ b/drivers/firewire/core-transaction.c
@@ -777,7 +777,7 @@ static struct fw_request *allocate_request(struct fw_card *card,
 		return NULL;
 	}
 
-	request = kmalloc(sizeof(*request) + length, GFP_ATOMIC);
+	request = kmalloc(struct_size(*request, data, length), GFP_ATOMIC);
 	if (request == NULL)
 		return NULL;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-01-28 14:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-28  8:03 [PATCH] drivers/firewire: use struct_size over open coded arithmetic cgel.zte
2022-01-28 12:08 ` kernel test robot
2022-01-28 12:08   ` kernel test robot
2022-01-28 14:54 ` kernel test robot
2022-01-28 14:54   ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.