Skip to content

Commit 07cce74

Browse files
vireshkrafaeljw
authored andcommitted
PM / OPP: handle allocation of device_opp in a separate routine
Get the 'device_opp' allocation code into a separate routine to keep only the necessary part in dev_pm_opp_add_dynamic(). Also do s/sizeof(struct device_opp)/sizeof(*dev_opp) and remove the print message on kzalloc() failure as checkpatch warns for that. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 29df0ee commit 07cce74

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

drivers/base/power/opp.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,27 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
386386
}
387387
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor);
388388

389+
static struct device_opp *add_device_opp(struct device *dev)
390+
{
391+
struct device_opp *dev_opp;
392+
393+
/*
394+
* Allocate a new device OPP table. In the infrequent case where a new
395+
* device is needed to be added, we pay this penalty.
396+
*/
397+
dev_opp = kzalloc(sizeof(*dev_opp), GFP_KERNEL);
398+
if (!dev_opp)
399+
return NULL;
400+
401+
dev_opp->dev = dev;
402+
srcu_init_notifier_head(&dev_opp->srcu_head);
403+
INIT_LIST_HEAD(&dev_opp->opp_list);
404+
405+
/* Secure the device list modification */
406+
list_add_rcu(&dev_opp->node, &dev_opp_list);
407+
return dev_opp;
408+
}
409+
389410
static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq,
390411
unsigned long u_volt, bool dynamic)
391412
{
@@ -412,27 +433,13 @@ static int dev_pm_opp_add_dynamic(struct device *dev, unsigned long freq,
412433
/* Check for existing list for 'dev' */
413434
dev_opp = find_device_opp(dev);
414435
if (IS_ERR(dev_opp)) {
415-
/*
416-
* Allocate a new device OPP table. In the infrequent case
417-
* where a new device is needed to be added, we pay this
418-
* penalty.
419-
*/
420-
dev_opp = kzalloc(sizeof(struct device_opp), GFP_KERNEL);
436+
dev_opp = add_device_opp(dev);
421437
if (!dev_opp) {
422438
mutex_unlock(&dev_opp_list_lock);
423439
kfree(new_opp);
424-
dev_warn(dev,
425-
"%s: Unable to create device OPP structure\n",
426-
__func__);
427440
return -ENOMEM;
428441
}
429442

430-
dev_opp->dev = dev;
431-
srcu_init_notifier_head(&dev_opp->srcu_head);
432-
INIT_LIST_HEAD(&dev_opp->opp_list);
433-
434-
/* Secure the device list modification */
435-
list_add_rcu(&dev_opp->node, &dev_opp_list);
436443
head = &dev_opp->opp_list;
437444
goto list_add;
438445
}

0 commit comments

Comments
 (0)