diff options
author | Maxime Ripard <maxime.ripard@free-electrons.com> | 2015-09-30 08:36:31 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2015-10-04 07:09:43 -0400 |
commit | fb727077b04f768d0c79d9aa29e958262a9e3d9e (patch) | |
tree | c2e6b283f38ec0aa7cdf790bae2b941901b41b5e /drivers/nvmem | |
parent | ace22170655f61d82fff95e57d673bf847a32a03 (diff) |
nvmem: sunxi: Check for memory allocation failure
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>
Diffstat (limited to 'drivers/nvmem')
-rw-r--r-- | drivers/nvmem/sunxi_sid.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/drivers/nvmem/sunxi_sid.c b/drivers/nvmem/sunxi_sid.c index 14777dd5212d..cfa3b85064dd 100644 --- a/drivers/nvmem/sunxi_sid.c +++ b/drivers/nvmem/sunxi_sid.c | |||
@@ -103,7 +103,7 @@ static int sunxi_sid_probe(struct platform_device *pdev) | |||
103 | struct nvmem_device *nvmem; | 103 | struct nvmem_device *nvmem; |
104 | struct regmap *regmap; | 104 | struct regmap *regmap; |
105 | struct sunxi_sid *sid; | 105 | struct sunxi_sid *sid; |
106 | int i, size; | 106 | int ret, i, size; |
107 | char *randomness; | 107 | char *randomness; |
108 | 108 | ||
109 | sid = devm_kzalloc(dev, sizeof(*sid), GFP_KERNEL); | 109 | sid = devm_kzalloc(dev, sizeof(*sid), GFP_KERNEL); |
@@ -131,6 +131,11 @@ static int sunxi_sid_probe(struct platform_device *pdev) | |||
131 | return PTR_ERR(nvmem); | 131 | return PTR_ERR(nvmem); |
132 | 132 | ||
133 | randomness = kzalloc(sizeof(u8) * size, GFP_KERNEL); | 133 | randomness = kzalloc(sizeof(u8) * size, GFP_KERNEL); |
134 | if (!randomness) { | ||
135 | ret = -EINVAL; | ||
136 | goto err_unreg_nvmem; | ||
137 | } | ||
138 | |||
134 | for (i = 0; i < size; i++) | 139 | for (i = 0; i < size; i++) |
135 | randomness[i] = sunxi_sid_read_byte(sid, i); | 140 | randomness[i] = sunxi_sid_read_byte(sid, i); |
136 | 141 | ||
@@ -140,6 +145,10 @@ static int sunxi_sid_probe(struct platform_device *pdev) | |||
140 | platform_set_drvdata(pdev, nvmem); | 145 | platform_set_drvdata(pdev, nvmem); |
141 | 146 | ||
142 | return 0; | 147 | return 0; |
148 | |||
149 | err_unreg_nvmem: | ||
150 | nvmem_unregister(nvmem); | ||
151 | return ret; | ||
143 | } | 152 | } |
144 | 153 | ||
145 | static int sunxi_sid_remove(struct platform_device *pdev) | 154 | static int sunxi_sid_remove(struct platform_device *pdev) |