Skip to contentSkip to conversation

tegra-hsp: fix a missing-check bug in tegra_hsp_doorbell_create()

PATCH In review Gen Zhang 2 participants 3 messages May 27, 2019

Subsystems (2)
lore
Share & tools
lore

Gen Zhang

author
#0 lore raw

PATCH 1/1 tegra-hsp: fix a missing-check bug in tegra_hsp_doorbell_create()

In tegra_hsp_doorbell_create(), 'db->name' is allocated by devm_kstrdup_const(). It returns NULL when fails. So 'db->name' should be checked.

---

drivers/mailbox/tegra-hsp.c +2 -0
index 11fc9fd..b613c46 100644
@@ -292,6 +292,8 @@ tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name,
 	db->channel.hsp = hsp;
 
 	db->name = devm_kstrdup_const(hsp->dev, name, GFP_KERNEL);
+	if (!db->name)
+		return ERR_PTR(-ENOMEM);
 	db->master = master;
 	db->index = index;
 

---

Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Gen Zhang

In tegra_hsp_doorbell_create(), 'db->name' is allocated by devm_kstrdup_const(). It returns NULL when fails. So 'db->name' should be checked.

---

drivers/mailbox/tegra-hsp.c +0 -0
index 11fc9fd..b613c46 100644

drivers/mailbox/tegra-hsp.c tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name, · line 296

Quoted 5 lines
drivers/mailbox/tegra-hsp.c +2 -0
@@ -292,6 +292,8 @@ tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name,
 	db->channel.hsp = hsp;
 
 	db->name = devm_kstrdup_const(hsp->dev, name, GFP_KERNEL);
+	if (!db->name)
+		return ERR_PTR(-ENOMEM);

I don't think this could ever happen, since name is always from .rodata and hence devm_kstrdup_const() never returns NULL. But formally this is correct, so:

author
#2 lore raw
Quoted 22 lines · Thierry Reding
Quoted 11 lines · Gen Zhang

In tegra_hsp_doorbell_create(), 'db->name' is allocated by devm_kstrdup_const(). It returns NULL when fails. So 'db->name' should be checked.

---

drivers/mailbox/tegra-hsp.c +0 -0
index 11fc9fd..b613c46 100644

drivers/mailbox/tegra-hsp.c tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name, · line 296

Quoted 5 lines
drivers/mailbox/tegra-hsp.c +2 -0
@@ -292,6 +292,8 @@ tegra_hsp_doorbell_create(struct tegra_hsp *hsp, const char *name,
 	db->channel.hsp = hsp;
 
 	db->name = devm_kstrdup_const(hsp->dev, name, GFP_KERNEL);
+	if (!db->name)
+		return ERR_PTR(-ENOMEM);

I don't think this could ever happen, since name is always from .rodata and hence devm_kstrdup_const() never returns NULL. But formally this is correct, so:

Quoted 1 line

Thanks for your reply, Thierry.

Thanks
Gen