diff mbox

[v2,1/2] cpufreq: powernv: Check for devm_kzalloc() failure

Message ID 1521906759-6856-1-git-send-email-festevam@gmail.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Fabio Estevam March 24, 2018, 3:52 p.m. UTC
From: Fabio Estevam <fabio.estevam@nxp.com>

kmalloc() may fail, so we should better check for error and
propagate the error in the case of allocation failure.

This avoids a potential NULL pointer dereference later on.

Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
---
Changes since v1:
- s/devm_kzalloc/kmalloc in the commit log

 drivers/cpufreq/powernv-cpufreq.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox

Patch

diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index 0591874..4ddfec9 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -329,6 +329,8 @@  static int init_powernv_pstates(void)
 
 		revmap_data = (struct pstate_idx_revmap_data *)
 			      kmalloc(sizeof(*revmap_data), GFP_KERNEL);
+		if (!revmap_data)
+			return -ENOMEM;
 
 		revmap_data->pstate_id = id & 0xFF;
 		revmap_data->cpufreq_table_idx = i;