Skip to contentSkip to conversation

devfreq: correctly check failed allocation

PATCH MyungJoo Ham 1 participant 1 message Oct 21, 2015

lore
Share & tools
lore
#0 lore raw
Quoted 30 lines · MyungJoo Ham
Quoted 14 lines

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 +0 -0
index ca1b362..814089f 100644

drivers/devfreq/devfreq.c struct devfreq *devfreq_add_device(struct device *dev, · line 491

Quoted 10 lines
drivers/devfreq/devfreq.c +7 -0
@@ -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;
+      }
+

I don't see a label 'err_dev' in devfreq.c
And please note that you are under a mutex lock here as well; you must unlock it before returning.
Oh, I think I need to unlock.

Quoted 9 lines

For devfreq.c of most recent release candidate, please refer to
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/drivers/devfreq/devfreq.c?id=7379047d5585187d1288486d4627873170d0005a

Sorry I used older version of linux. I will resend patch for current version.

You don't seem to be based on a recent RC as well.

I cannot understand what RC means.

It's Release Candidate. Please refer to the git tags in the repo.

Quoted 2 lines

And question is that, when device_register fails, it returns without freeing devfreq. Is it fine?

We have a "release" callback defined for the struct device registered with device_register(), which is called when that happens.

Cheers,
MyungJoo