Skip to contentSkip to conversation

ASoC: samsung: i2s: check the return value of kstrdup()

PATCH Superseded [email protected] 2 participants 2 messages Feb 22, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: samsung: i2s: check the return value of kstrdup()

From: Xiaoke Wang <[email protected]>

kstrdup() is a memory allocation function which can return NULL when some internal memory errors happen. It is better to check the return value of it to catch the error in time.

---
 sound/soc/samsung/i2s.c | 4 ++++
 1 file changed, 4 insertions(+)
sound/soc/samsung/i2s.c +4 -0
index 309badc..70c8271 100644
@@ -1349,6 +1349,10 @@ static int i2s_create_secondary_device(struct samsung_i2s_priv *priv)
 		return -ENOMEM;
 
 	pdev_sec->driver_override = kstrdup("samsung-i2s", GFP_KERNEL);
+	if (!pdev_sec->driver_override) {
+		platform_device_put(pdev_sec);
+		return -ENOMEM;
+	}
 
 	ret = platform_device_add(pdev_sec);
 	if (ret < 0) {
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · On 22/02/2022 12:53, [email protected] wrote:

From: Xiaoke Wang <[email protected]>

kstrdup() is a memory allocation function which can return NULL when some internal memory errors happen. It is better to check the return value of it to catch the error in time.

---
 sound/soc/samsung/i2s.c | 4 ++++
 1 file changed, 4 insertions(+)

Best regards,
Krzysztof