Skip to contentSkip to conversation

i2c: brcmstb: allocate correct amount of memory for regmap

PATCH New Wolfram Sang 4 participants 6 messages Feb 21, 2016 – Mar 1, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: brcmstb: allocate correct amount of memory for regmap

We want the size of the struct, not of a pointer to it. To be future proof, just dereference the pointer to get the desired type.

---
 drivers/i2c/busses/i2c-brcmstb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/i2c/busses/i2c-brcmstb.c +1 -2
index 3711df1d452622..4a45408dd82060 100644
@@ -586,8 +586,7 @@ static int brcmstb_i2c_probe(struct platform_device *pdev)
 	if (!dev)
 		return -ENOMEM;
 
-	dev->bsc_regmap = devm_kzalloc(&pdev->dev, sizeof(struct bsc_regs *),
-				       GFP_KERNEL);
+	dev->bsc_regmap = devm_kzalloc(&pdev->dev, sizeof(*dev->bsc_regmap), GFP_KERNEL);
 	if (!dev->bsc_regmap)
 		return -ENOMEM;
 
Signature · 1 line
2.7.0
#1 lore raw

PATCH 1/1 i2c: brcmstb: allocate correct amount of memory for regmap

Quoted 2 lines · Wolfram Sang

We want the size of the struct, not of a pointer to it. To be future proof, just dereference the pointer to get the desired type.

This looks like it fixes like a fairly serious issue: before this change, the driver may modify memory that wasn't allocated for this struct. Shouldn't this also have Cc: stable?

Quoted 2 lines
#2 lore raw

PATCH 1/1 i2c: brcmstb: allocate correct amount of memory for regmap

Quoted 7 lines · Gregory Fong
Quoted 2 lines · Wolfram Sang

We want the size of the struct, not of a pointer to it. To be future proof, just dereference the pointer to get the desired type.

This looks like it fixes like a fairly serious issue: before this change, the driver may modify memory that wasn't allocated for this struct. Shouldn't this also have Cc: stable?

Surely. I usually add the tag when committing, not when sending out.

Quoted 2 lines
Quoted 1 line

Thanks.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160222/544259df/attachment.sig>

#3 lore raw

PATCH 1/1 i2c: brcmstb: allocate correct amount of memory for regmap

In reply to Wolfram Sang

Le 21/02/2016 06:16, Wolfram Sang a ?crit :

Quoted 4 lines

We want the size of the struct, not of a pointer to it. To be future proof, just dereference the pointer to get the desired type.

Fixes dd1aa2524bc5 ("i2c: brcmstb: Add Broadcom settop SoC i2c

controller driver")

Thanks!

Signature · 1 line
Florian
maintainer
#4 lore raw

PATCH 1/1 i2c: brcmstb: allocate correct amount of memory for regmap

Quoted 2 lines

We want the size of the struct, not of a pointer to it. To be future proof, just dereference the pointer to get the desired type.

Thanks for catching and fixing this.

Quoted 2 lines

Kamal

author Applied
#5 lore raw

PATCH 1/1 i2c: brcmstb: allocate correct amount of memory for regmap

In reply to Wolfram Sang
Quoted 4 lines · Wolfram Sang

We want the size of the struct, not of a pointer to it. To be future proof, just dereference the pointer to get the desired type.

Applied to for-current with stable tag added, thanks!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160301/27b2c0c2/attachment-0001.sig>