Skip to content

Commit

Permalink
nvmem: sunxi: Check for memory allocation failure
Browse files Browse the repository at this point in the history
The sunxi_sid driver doesn't check for kmalloc return status before
derefencing the returned pointer, which could lead to a NULL pointer
dereference if kmalloc failed. Check for its return code to make sure it
deosn't happen.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Maxime Ripard authored and Greg Kroah-Hartman committed Oct 4, 2015
1 parent ace2217 commit fb72707
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion drivers/nvmem/sunxi_sid.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static int sunxi_sid_probe(struct platform_device *pdev)
struct nvmem_device *nvmem;
struct regmap *regmap;
struct sunxi_sid *sid;
int i, size;
int ret, i, size;
char *randomness;

sid = devm_kzalloc(dev, sizeof(*sid), GFP_KERNEL);
Expand Down Expand Up @@ -131,6 +131,11 @@ static int sunxi_sid_probe(struct platform_device *pdev)
return PTR_ERR(nvmem);

randomness = kzalloc(sizeof(u8) * size, GFP_KERNEL);
if (!randomness) {
ret = -EINVAL;
goto err_unreg_nvmem;
}

for (i = 0; i < size; i++)
randomness[i] = sunxi_sid_read_byte(sid, i);

Expand All @@ -140,6 +145,10 @@ static int sunxi_sid_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, nvmem);

return 0;

err_unreg_nvmem:
nvmem_unregister(nvmem);
return ret;
}

static int sunxi_sid_remove(struct platform_device *pdev)
Expand Down

0 comments on commit fb72707

Please sign in to comment.