Skip to contentSkip to conversation

devfreq: correctly check failed allocation

PATCH New Insu Yun 1 participant 1 message Oct 19, 2015 Device frequency (devfreq)

lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH 1/1 devfreq: correctly check failed allocation

Since devm_kzalloc can be failed in memory pressure, check return value and handle error.

---
 drivers/devfreq/devfreq.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/devfreq/devfreq.c +14 -0
index ca1b362..814089f 100644
@@ -482,9 +482,23 @@ struct devfreq *devfreq_add_device(struct device *dev,
 						devfreq->profile->max_state *
 						devfreq->profile->max_state,
 						GFP_KERNEL);
+	if (!devfreq->trans_table) {
+		dev_err(dev, "%s: Unable to create transition table for the device\n",
+			__func__);
+		err = -ENOMEM;
+		goto err_dev;
+	}
+
 	devfreq->time_in_state = devm_kzalloc(dev, sizeof(unsigned int) *
 						devfreq->profile->max_state,
 						GFP_KERNEL);
+	if (!devfreq->time_in_state) {
+		dev_err(dev, "%s: Unable to create state for the device\n",
+			__func__);
+		err = -ENOMEM;
+		goto err_dev;
+	}
+
 	devfreq->last_stat_updated = jiffies;
 
 	dev_set_name(&devfreq->dev, "%s", dev_name(dev));
Signature · 1 line
1.9.1