[PATCH v19 01/10] power: reset: reboot-mode: Remove devres based allocations
Shivendra Pratap
shivendra.pratap at oss.qualcomm.com
Mon Jan 5 09:53:56 PST 2026
On 1/2/2026 3:35 PM, Bartosz Golaszewski wrote:
> On Sun, Dec 28, 2025 at 6:20 PM Shivendra Pratap
> <shivendra.pratap at oss.qualcomm.com> wrote:
>>
>> Devres APIs are intended for use in drivers, where the managed lifetime
>> of resources is tied directly to the driver attach/detach cycle. In
>> shared subsystem code, there is no guarantee that the subsystem
>> functions will only be called after a driver has been attached, nor that
>> they will not be referenced after the managed resources have been
>> released during driver detach.
[SNIP..]
>>
>> @@ -71,9 +74,11 @@ static int reboot_mode_notify(struct notifier_block *this,
>> int reboot_mode_register(struct reboot_mode_driver *reboot)
>> {
>> struct mode_info *info;
>> + struct mode_info *next;
>> struct property *prop;
>> struct device_node *np = reboot->dev->of_node;
>> size_t len = strlen(PREFIX);
>> + u32 magic;
>> int ret;
>>
>> INIT_LIST_HEAD(&reboot->head);
>> @@ -82,19 +87,17 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
>> if (strncmp(prop->name, PREFIX, len))
>> continue;
>>
>> - info = devm_kzalloc(reboot->dev, sizeof(*info), GFP_KERNEL);
>> + if (of_property_read_u32(np, prop->name, &magic)) {
>
> Please use device_property_read_u32() if you have access to a device struct.
Ack. Can it go in same patch with the fixes tag?
>
>> + pr_err("reboot mode %s without magic number\n", prop->name);
>
> If this is an error, shouldn't we bail out?
>
>> + continue;
>> + }
>> +
>> + info = kzalloc(sizeof(*info), GFP_KERNEL);
>> if (!info) {
>> ret = -ENOMEM;
>> goto error;
>> }
>>
>> - if (of_property_read_u32(np, prop->name, &info->magic)) {
>> - dev_err(reboot->dev, "reboot mode %s without magic number\n",
>> - info->mode);
>> - devm_kfree(reboot->dev, info);
>> - continue;
>> - }
>> -
>> info->mode = kstrdup_const(prop->name + len, GFP_KERNEL);
>> if (!info->mode) {
>> ret = -ENOMEM;
>> @@ -102,8 +105,7 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
>> } else if (info->mode[0] == '\0') {
>> kfree_const(info->mode);
>> ret = -EINVAL;
>> - dev_err(reboot->dev, "invalid mode name(%s): too short!\n",
>> - prop->name);
>> + pr_err("invalid mode name(%s): too short!\n", prop->name);
>> goto error;
>> }
>>
>> @@ -116,8 +118,12 @@ int reboot_mode_register(struct reboot_mode_driver *reboot)
>> return 0;
>>
>> error:
>> - list_for_each_entry(info, &reboot->head, list)
>> + kfree(info);
>> + list_for_each_entry_safe(info, next, &reboot->head, list) {
>> + list_del(&info->list);
>> kfree_const(info->mode);
>> + kfree(info);
>> + }
>>
>> return ret;
>> }
>> @@ -130,11 +136,15 @@ EXPORT_SYMBOL_GPL(reboot_mode_register);
>> int reboot_mode_unregister(struct reboot_mode_driver *reboot)
>> {
>> struct mode_info *info;
>> + struct mode_info *next;
>>
>> unregister_reboot_notifier(&reboot->reboot_notifier);
>>
>> - list_for_each_entry(info, &reboot->head, list)
>> + list_for_each_entry_safe(info, next, &reboot->head, list) {
>> + list_del(&info->list);
>> kfree_const(info->mode);
>> + kfree(info);
>> + }
>
> The code is repeated here, maybe factor it out into a separate function?
Ack. let me try that.
thanks,
Shivendra
More information about the linux-arm-kernel
mailing list