diff mbox

i2c: brcmstb: allocate correct amount of memory for regmap

Message ID 1456064238-6294-1-git-send-email-wsa@the-dreams.de (mailing list archive)
State New, archived
Headers show

Commit Message

Wolfram Sang Feb. 21, 2016, 2:16 p.m. UTC
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.

Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
---
 drivers/i2c/busses/i2c-brcmstb.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Gregory Fong Feb. 22, 2016, 6:33 a.m. UTC | #1
On Sun, Feb 21, 2016 at 6:16 AM, Wolfram Sang <wsa@the-dreams.de> wrote:
> 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?

>
> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

Acked-by: Gregory Fong <gregory.0xf0@gmail.com>
Wolfram Sang Feb. 22, 2016, 8:05 a.m. UTC | #2
On Sun, Feb 21, 2016 at 10:33:14PM -0800, Gregory Fong wrote:
> On Sun, Feb 21, 2016 at 6:16 AM, Wolfram Sang <wsa@the-dreams.de> wrote:
> > 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.

> > Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
> Acked-by: Gregory Fong <gregory.0xf0@gmail.com>

Thanks.
Florian Fainelli Feb. 22, 2016, 4:42 p.m. UTC | #3
Le 21/02/2016 06:16, Wolfram Sang a écrit :
> 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.
> 
> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

Fixes: dd1aa2524bc5 ("i2c: brcmstb: Add Broadcom settop SoC i2c
controller driver")

Acked-by: Florian Fainelli <f.fainelli@gmail.com>

Thanks!
Kamal Dasu Feb. 25, 2016, 8:08 p.m. UTC | #4
> 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.

>
> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

Reviewed-by: Kamal Dasu <kdasu.kdev@gmail.com>

Kamal
Wolfram Sang March 1, 2016, 6:19 p.m. UTC | #5
On Sun, Feb 21, 2016 at 03:16:48PM +0100, Wolfram Sang wrote:
> 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.
> 
> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

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

Patch

diff --git a/drivers/i2c/busses/i2c-brcmstb.c b/drivers/i2c/busses/i2c-brcmstb.c
index 3711df1d452622..4a45408dd82060 100644
--- a/drivers/i2c/busses/i2c-brcmstb.c
+++ b/drivers/i2c/busses/i2c-brcmstb.c
@@ -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;