mtd: oxnas_nand: Allocating more than necessary in probe()
diff mbox

Message ID 20170425091949.uindhaxmbtsksqc7@mwanda
State New
Headers show

Commit Message

Dan Carpenter April 25, 2017, 9:19 a.m. UTC
We only need to allocate sizeof(struct oxnas_nand_ctrl) which is 192
bytes and not sizeof(struct nand_chip) which is a much larger 3056
bytes.

Fixes: 668592492409 ("mtd: nand: Add OX820 NAND Support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Comments

Boris BREZILLON May 2, 2017, 4:19 p.m. UTC | #1
On Tue, 25 Apr 2017 12:19:49 +0300
Dan Carpenter <dan.carpenter@oracle.com> wrote:

> We only need to allocate sizeof(struct oxnas_nand_ctrl) which is 192
> bytes and not sizeof(struct nand_chip) which is a much larger 3056
> bytes.
> 
> Fixes: 668592492409 ("mtd: nand: Add OX820 NAND Support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>

> 
> diff --git a/drivers/mtd/nand/oxnas_nand.c b/drivers/mtd/nand/oxnas_nand.c
> index 3e3bf3b364d2..1b207aac840c 100644
> --- a/drivers/mtd/nand/oxnas_nand.c
> +++ b/drivers/mtd/nand/oxnas_nand.c
> @@ -91,7 +91,7 @@ static int oxnas_nand_probe(struct platform_device *pdev)
>  	int err = 0;
>  
>  	/* Allocate memory for the device structure (and zero it) */
> -	oxnas = devm_kzalloc(&pdev->dev, sizeof(struct nand_chip),
> +	oxnas = devm_kzalloc(&pdev->dev, sizeof(*oxnas),
>  			     GFP_KERNEL);
>  	if (!oxnas)
>  		return -ENOMEM;
Brian Norris May 3, 2017, 1:58 a.m. UTC | #2
On Tue, Apr 25, 2017 at 12:19:49PM +0300, Dan Carpenter wrote:
> We only need to allocate sizeof(struct oxnas_nand_ctrl) which is 192
> bytes and not sizeof(struct nand_chip) which is a much larger 3056
> bytes.
> 
> Fixes: 668592492409 ("mtd: nand: Add OX820 NAND Support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Applied to l2-mtd.git

Patch
diff mbox

diff --git a/drivers/mtd/nand/oxnas_nand.c b/drivers/mtd/nand/oxnas_nand.c
index 3e3bf3b364d2..1b207aac840c 100644
--- a/drivers/mtd/nand/oxnas_nand.c
+++ b/drivers/mtd/nand/oxnas_nand.c
@@ -91,7 +91,7 @@  static int oxnas_nand_probe(struct platform_device *pdev)
 	int err = 0;
 
 	/* Allocate memory for the device structure (and zero it) */
-	oxnas = devm_kzalloc(&pdev->dev, sizeof(struct nand_chip),
+	oxnas = devm_kzalloc(&pdev->dev, sizeof(*oxnas),
 			     GFP_KERNEL);
 	if (!oxnas)
 		return -ENOMEM;