Skip to content

Commit b57100a

Browse files
Malaya Kumar Routrafaeljw
authored andcommitted
PM: console: Fix memory allocation error handling in pm_vt_switch_required()
The pm_vt_switch_required() function fails silently when memory allocation fails, offering no indication to callers that the operation was unsuccessful. This behavior prevents drivers from handling allocation errors correctly or implementing retry mechanisms. By ensuring that failures are reported back to the caller, drivers can make informed decisions, improve robustness, and avoid unexpected behavior during critical power management operations. Change the function signature to return an integer error code and modify the implementation to return -ENOMEM when kmalloc() fails. Update both the function declaration and the inline stub in include/linux/pm.h to maintain consistency across CONFIG_VT_CONSOLE_SLEEP configurations. The function now returns: - 0 on success (including when updating existing entries) - -ENOMEM when memory allocation fails This change improves error reporting without breaking existing callers, as the current callers in drivers/video/fbdev/core/fbmem.c already ignore the return value, making this a backward-compatible improvement. Reviewed-by: Lyude Paul <lyude@redhat.com> Signed-off-by: Malaya Kumar Rout <mrout@redhat.com> Reviewed-by: Dhruva Gole <d-gole@ti.com> Reviewed-by: Lyude Paul <lyude@redhat.com> Link: https://patch.msgid.link/20251013193028.89570-1-mrout@redhat.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 67434ce commit b57100a

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

include/linux/pm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ extern void (*pm_power_off)(void);
2525

2626
struct device; /* we have a circular dep with device.h */
2727
#ifdef CONFIG_VT_CONSOLE_SLEEP
28-
extern void pm_vt_switch_required(struct device *dev, bool required);
28+
extern int pm_vt_switch_required(struct device *dev, bool required);
2929
extern void pm_vt_switch_unregister(struct device *dev);
3030
#else
31-
static inline void pm_vt_switch_required(struct device *dev, bool required)
31+
static inline int pm_vt_switch_required(struct device *dev, bool required)
3232
{
33+
return 0;
3334
}
3435
static inline void pm_vt_switch_unregister(struct device *dev)
3536
{

kernel/power/console.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ static LIST_HEAD(pm_vt_switch_list);
4444
* no_console_suspend argument has been passed on the command line, VT
4545
* switches will occur.
4646
*/
47-
void pm_vt_switch_required(struct device *dev, bool required)
47+
int pm_vt_switch_required(struct device *dev, bool required)
4848
{
4949
struct pm_vt_switch *entry, *tmp;
50+
int ret = 0;
5051

5152
mutex_lock(&vt_switch_mutex);
5253
list_for_each_entry(tmp, &pm_vt_switch_list, head) {
@@ -58,15 +59,18 @@ void pm_vt_switch_required(struct device *dev, bool required)
5859
}
5960

6061
entry = kmalloc(sizeof(*entry), GFP_KERNEL);
61-
if (!entry)
62+
if (!entry) {
63+
ret = -ENOMEM;
6264
goto out;
65+
}
6366

6467
entry->required = required;
6568
entry->dev = dev;
6669

6770
list_add(&entry->head, &pm_vt_switch_list);
6871
out:
6972
mutex_unlock(&vt_switch_mutex);
73+
return ret;
7074
}
7175
EXPORT_SYMBOL(pm_vt_switch_required);
7276

0 commit comments

Comments
 (0)