From: Arnd Bergmann <arnd@kernel.org>
To: Matan Ziv-Av <matan@svgalib.org>,
Hans de Goede <hdegoede@redhat.com>,
Mark Gross <mgross@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] platform/x86: lg-laptop: Fix possible NULL pointer derefence
Date: Mon, 20 Sep 2021 11:55:50 +0200 [thread overview]
Message-ID: <20210920095556.1175269-1-arnd@kernel.org> (raw)
From: Arnd Bergmann <arnd@arndb.de>
When CONFIG_DMI is disabled, dmi_get_system_info() returns a NULL
pointer, which is now caught by a warning:
In function 'strlen',
inlined from 'acpi_add.part.0' at drivers/platform/x86/lg-laptop.c:658:6:
include/linux/fortify-string.h:25:33: error: argument 1 null where non-null expected [-Werror=nonnull]
25 | #define __underlying_strlen __builtin_strlen
| ^
include/linux/fortify-string.h:60:24: note: in expansion of macro '__underlying_strlen'
60 | return __underlying_strlen(p);
| ^~~~~~~~~~~~~~~~~~~
drivers/platform/x86/lg-laptop.c: In function 'acpi_add.part.0':
include/linux/fortify-string.h:25:33: note: in a call to built-in function '__builtin_strlen'
25 | #define __underlying_strlen __builtin_strlen
| ^
include/linux/fortify-string.h:60:24: note: in expansion of macro '__underlying_strlen'
60 | return __underlying_strlen(p);
| ^~~~~~~~~~~~~~~~~~~
The code in there does not appear essential, so an explicit
NULL check should be sufficient. The string is also printed
to the console, but printk() is able to handle NULL pointer
arguments gracefully.
Fixes: 8983bfd58d61 ("platform/x86: lg-laptop: Support for battery charge limit on newer models")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/platform/x86/lg-laptop.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/platform/x86/lg-laptop.c b/drivers/platform/x86/lg-laptop.c
index 3e520d5bca07..88b551caeaaf 100644
--- a/drivers/platform/x86/lg-laptop.c
+++ b/drivers/platform/x86/lg-laptop.c
@@ -655,7 +655,7 @@ static int acpi_add(struct acpi_device *device)
goto out_platform_registered;
}
product = dmi_get_system_info(DMI_PRODUCT_NAME);
- if (strlen(product) > 4)
+ if (product && strlen(product) > 4)
switch (product[4]) {
case '5':
case '6':
--
2.29.2
next reply other threads:[~2021-09-20 9:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-20 9:55 Arnd Bergmann [this message]
2021-09-20 17:45 ` [PATCH] platform/x86: lg-laptop: Fix possible NULL pointer derefence Mark Gross
2021-09-21 10:12 ` Hans de Goede
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210920095556.1175269-1-arnd@kernel.org \
--to=arnd@kernel.org \
--cc=arnd@arndb.de \
--cc=hdegoede@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matan@svgalib.org \
--cc=mgross@linux.intel.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=rafael.j.wysocki@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).