* [PATCH next] drivers/hwtracing/intel_th: Replace kzalloc(... strlen()...) with kzalloc_flex()
@ 2026-06-08 9:55 david.laight.linux
0 siblings, 0 replies; only message in thread
From: david.laight.linux @ 2026-06-08 9:55 UTC (permalink / raw)
To: Kees Cook, linux-hardening, linux-kernel
Cc: Arnd Bergmann, Alexander Shishkin, David Laight
From: David Laight <david.laight.linux@gmail.com>
Save the result of the strlen() and use memcpy() instead of strcpy() to
copy the string.
Signed-off-by: David Laight <david.laight.linux@gmail.com>
---
This is one of a group of patches that remove potentially unbounded
strcpy() calls.
They are mostly replaced by strscpy() or, when strlen() has just been
called, with memcpy() (usually including the '\0').
Calls with copy string literals into arrays are left unchanged.
They are safe and easily detected as such.
The changes were made by getting the compiler to detect the calls and
then fixing the code by hand.
Note that all the changes are only compile tested.
Some Makefiles were changed to allow files to contain strcpy().
As well as 'difficult to fix' files, this included 'show' functions
as they really need to use sysfs_emit() or seq_printf().
All the patches are being sent individually to avoid very long cc lists.
Apologies for the terse commit messages and likely unexpected tags.
(There are about 100 patches in total.)
drivers/hwtracing/intel_th/core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/hwtracing/intel_th/core.c b/drivers/hwtracing/intel_th/core.c
index 3924e63e2eee..711a54e22e87 100644
--- a/drivers/hwtracing/intel_th/core.c
+++ b/drivers/hwtracing/intel_th/core.c
@@ -374,20 +374,21 @@ intel_th_device_alloc(struct intel_th *th, unsigned int type, const char *name,
{
struct device *parent;
struct intel_th_device *thdev;
+ size_t name_len = strlen(name) + 1;
if (type == INTEL_TH_OUTPUT)
parent = &th->hub->dev;
else
parent = th->dev;
- thdev = kzalloc(sizeof(*thdev) + strlen(name) + 1, GFP_KERNEL);
+ thdev = kzalloc_flex(*thdev, name, name_len);
if (!thdev)
return NULL;
thdev->id = id;
thdev->type = type;
- strcpy(thdev->name, name);
+ memcpy(thdev->name, name, name_len);
device_initialize(&thdev->dev);
thdev->dev.bus = &intel_th_bus;
thdev->dev.type = intel_th_device_type[type];
--
2.39.5
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-06-08 9:55 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-08 9:55 [PATCH next] drivers/hwtracing/intel_th: Replace kzalloc(... strlen()...) with kzalloc_flex() david.laight.linux
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.