From nobody Mon Apr 6 10:31:51 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 616032561A2 for ; Mon, 13 Oct 2025 19:30:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760383850; cv=none; b=B5Ecj24MFB1KZI+ezgJ3IrKfIbfs2oj8m6CauVNgm29oJOWy2UAUBzNn2j9Up1dx5deg4+pjK8LjYmusLyZEzesKv2jUvfsT5vwpfG6yilhHgvOL/rbYfLY147G3mCMYVNg8FdenKAGEpFST2EiPJSoPzKlmCekPlOoWAvA3zv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760383850; c=relaxed/simple; bh=k8L9EYVq4ZcGBQxGjh4u5oQtIJQX+iDffThzcZuRlZw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Buoiv/OvmEOohxZvlVcFu6j4F44dFUNu64lQHQbzLTVfLYnSA0LTs7RhhUQ7FXMan+8Hjaz7/JUggUVY6aV+jCC4b4HQe0hC8NgazrygARdhfU0TL3OMJjJLs1kOMNHDx2nxpKJYSWPb90cYYAVA7AD14Iz+lRS5qRjJLSuDIZg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=d5zf4TLA; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="d5zf4TLA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760383847; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=qpGSyBJC0SfDABFt4fi6cbT29UFiUUF23XI7uRytY/Y=; b=d5zf4TLAOY3QfUmkjRZxVveSUvuSmRALcpjV2G/w3kacDze4BZyvr9dyNlK3hXiBcR2xX9 GoFUMW7JrTAvdnH4b4zBdza9E1iSDaUhSY5WM4lPds7/om6Lztjpwv6+GSnz1IMMvEW+NT gopDfqxEPyOeeLJhari15h44TKAYOxE= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-fPTpuas2NJ-EAciB-qVlCA-1; Mon, 13 Oct 2025 15:30:42 -0400 X-MC-Unique: fPTpuas2NJ-EAciB-qVlCA-1 X-Mimecast-MFC-AGG-ID: fPTpuas2NJ-EAciB-qVlCA_1760383840 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BA9781800576; Mon, 13 Oct 2025 19:30:40 +0000 (UTC) Received: from mrout-thinkpadp16vgen1.punetw6.csb (unknown [10.74.80.9]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6CD851955F21; Mon, 13 Oct 2025 19:30:35 +0000 (UTC) From: Malaya Kumar Rout To: linux-kernel@vger.kernel.org Cc: mrout@redhat.com, lyude@redhat.com, malayarout91@gmail.com, "Rafael J. Wysocki" , Len Brown , Pavel Machek , linux-pm@vger.kernel.org Subject: [PATCH] PM: console: Fix memory allocation error handling in pm_vt_switch_required() Date: Tue, 14 Oct 2025 01:00:27 +0530 Message-ID: <20251013193028.89570-1-mrout@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Malaya Kumar Rout Reviewed-by: Dhruva Gole --- include/linux/pm.h | 5 +++-- kernel/power/console.c | 8 ++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/linux/pm.h b/include/linux/pm.h index cc7b2dc28574..a72e42eec130 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -25,11 +25,12 @@ extern void (*pm_power_off)(void); =20 struct device; /* we have a circular dep with device.h */ #ifdef CONFIG_VT_CONSOLE_SLEEP -extern void pm_vt_switch_required(struct device *dev, bool required); +extern int pm_vt_switch_required(struct device *dev, bool required); extern void pm_vt_switch_unregister(struct device *dev); #else -static inline void pm_vt_switch_required(struct device *dev, bool required) +static inline int pm_vt_switch_required(struct device *dev, bool required) { + return 0; } static inline void pm_vt_switch_unregister(struct device *dev) { diff --git a/kernel/power/console.c b/kernel/power/console.c index 19c48aa5355d..a906a0ac0f9b 100644 --- a/kernel/power/console.c +++ b/kernel/power/console.c @@ -44,9 +44,10 @@ static LIST_HEAD(pm_vt_switch_list); * no_console_suspend argument has been passed on the command line, VT * switches will occur. */ -void pm_vt_switch_required(struct device *dev, bool required) +int pm_vt_switch_required(struct device *dev, bool required) { struct pm_vt_switch *entry, *tmp; + int ret =3D 0; =20 mutex_lock(&vt_switch_mutex); list_for_each_entry(tmp, &pm_vt_switch_list, head) { @@ -58,8 +59,10 @@ void pm_vt_switch_required(struct device *dev, bool requ= ired) } =20 entry =3D kmalloc(sizeof(*entry), GFP_KERNEL); - if (!entry) + if (!entry) { + ret =3D -ENOMEM; goto out; + } =20 entry->required =3D required; entry->dev =3D dev; @@ -67,6 +70,7 @@ void pm_vt_switch_required(struct device *dev, bool requi= red) list_add(&entry->head, &pm_vt_switch_list); out: mutex_unlock(&vt_switch_mutex); + return ret; } EXPORT_SYMBOL(pm_vt_switch_required); =20 --=20 2.51.0