Skip to contentSkip to conversation

Convert media drivers to use devm_kmemdup_array()

PATCH Superseded Raag Jadav 2 participants 7 messages Feb 28, 2025 – Mar 11, 2025

Subsystems (5)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Raag Jadav

author
#0 lore raw

v2 cover Convert media drivers to use devm_kmemdup_array()

This series converts media drivers to use the newly introduced[1] devm_kmemdup_array() helper. This depends on changes available on immutable tag[2].

[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]

v2: Split patch series per subsystem

Raag Jadav (2):
media: atmel-isi: use devm_kmemdup_array()
media: stm32-dcmi: use devm_kmemdup_array()

 drivers/media/platform/atmel/atmel-isi.c     | 8 ++------
 drivers/media/platform/st/stm32/stm32-dcmi.c | 8 ++------
 2 files changed, 4 insertions(+), 12 deletions(-)

base-commit: b8c38ccb2ca52b9a38cfeb9f89abab5d6e713221

Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/2 media: atmel-isi: use devm_kmemdup_array()

Convert to use devm_kmemdup_array() and while at it, make the size robust against type changes.

---
 drivers/media/platform/atmel/atmel-isi.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/media/platform/atmel/atmel-isi.c +2 -6
index 0d1c39347529..7d8bec46af89 100644
@@ -1072,16 +1072,12 @@ static int isi_formats_init(struct atmel_isi *isi)
 		return -ENXIO;
 
 	isi->num_user_formats = num_fmts;
-	isi->user_formats = devm_kcalloc(isi->dev,
-					 num_fmts, sizeof(struct isi_format *),
-					 GFP_KERNEL);
+	isi->user_formats = devm_kmemdup_array(isi->dev, isi_fmts, num_fmts,
+					       sizeof(isi_fmts[0]), GFP_KERNEL);
 	if (!isi->user_formats)
 		return -ENOMEM;
 
-	memcpy(isi->user_formats, isi_fmts,
-	       num_fmts * sizeof(struct isi_format *));
 	isi->current_fmt = isi->user_formats[0];
-
 	return 0;
 }
 
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v2 2/2 media: stm32-dcmi: use devm_kmemdup_array()

In reply to Raag Jadav

Convert to use devm_kmemdup_array() and while at it, make the size robust against type changes.

---
 drivers/media/platform/st/stm32/stm32-dcmi.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/media/platform/st/stm32/stm32-dcmi.c +2 -6
index 9b699ee2b1e0..eedc15b30edc 100644
@@ -1682,18 +1682,14 @@ static int dcmi_formats_init(struct stm32_dcmi *dcmi)
 		return -ENXIO;
 
 	dcmi->num_of_sd_formats = num_fmts;
-	dcmi->sd_formats = devm_kcalloc(dcmi->dev,
-					num_fmts, sizeof(struct dcmi_format *),
-					GFP_KERNEL);
+	dcmi->sd_formats = devm_kmemdup_array(dcmi->dev, sd_fmts, num_fmts,
+					      sizeof(sd_fmts[0]), GFP_KERNEL);
 	if (!dcmi->sd_formats) {
 		dev_err(dcmi->dev, "Could not allocate memory\n");
 		return -ENOMEM;
 	}
 
-	memcpy(dcmi->sd_formats, sd_fmts,
-	       num_fmts * sizeof(struct dcmi_format *));
 	dcmi->sd_format = dcmi->sd_formats[0];
-
 	return 0;
 }
 
Signature · 1 line
2.34.1
#4 lore raw

Hi Raag,

Quoted 9 lines · Raag Jadav
Quoted 6 lines · Raag Jadav

This series converts media drivers to use the newly introduced[1] devm_kmemdup_array() helper. This depends on changes available on immutable tag[2].

[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]

Bump, anything I can do to move this forward?

The patches these depend on (those adding devm_kmemdup_array()) aren't in the Media tree yet. They don't seem urgent though so I'd just wait.

Speaking of the patches themselves: I'd use *array instead of array[0] for sizeof argument.

Signature · 3 lines
Regards,

Sakari Ailus
author
#5 lore raw
Quoted 8 lines · Sakari Ailus

Hi Raag,

Quoted 5 lines · Raag Jadav
Quoted 4 lines · Raag Jadav

This series converts media drivers to use the newly introduced[1] devm_kmemdup_array() helper. This depends on changes available on immutable tag[2].

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]

Bump, anything I can do to move this forward?

The patches these depend on (those adding devm_kmemdup_array()) aren't in the Media tree yet. They don't seem urgent though so I'd just wait.

I was hoping the immutable tag would be useful here. But sure, no problem.

Quoted 2 lines

Speaking of the patches themselves: I'd use *array instead of array[0] for sizeof argument.

I know it doesn't matter much to the compiler but since the source itself is an array here, doesn't [0] make more sense?

Raag

#6 lore raw

Hi Raag,

Quoted 17 lines · Raag Jadav
Quoted 8 lines · Sakari Ailus

Hi Raag,

Quoted 5 lines · Raag Jadav
Quoted 4 lines · Raag Jadav

This series converts media drivers to use the newly introduced[1] devm_kmemdup_array() helper. This depends on changes available on immutable tag[2].

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]

Bump, anything I can do to move this forward?

The patches these depend on (those adding devm_kmemdup_array()) aren't in the Media tree yet. They don't seem urgent though so I'd just wait.

Quoted 7 lines

I was hoping the immutable tag would be useful here. But sure, no problem.

Quoted 2 lines

Speaking of the patches themselves: I'd use *array instead of array[0] for sizeof argument.

I know it doesn't matter much to the compiler but since the source itself is an array here, doesn't [0] make more sense?

The element at index 0 isn't anyhow special in this respect so I do prefer *array instead. In practice it works either way of course.

Signature · 3 lines
Regards,

Sakari Ailus