Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2088533pxb; Mon, 20 Sep 2021 11:58:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwocNESPiOe4IHG72do+wDmictbiPU0I3eTwxv91XdJ8e+OqXEKb33fGdg86F4A/DSBqL7o X-Received: by 2002:a50:e10c:: with SMTP id h12mr18290575edl.299.1632164308063; Mon, 20 Sep 2021 11:58:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632164308; cv=none; d=google.com; s=arc-20160816; b=ROG7Q+sOESJT9w00HaLN7YUQCpDJUEaXx0cKq7xJvQJWtcFgHt17ig0TaPYA/IyhFj QhEoXagFGE7j3cuqC+hTsSJe0heqv0D6ifAKAu5YgQEyU/hIiCI0z9G+ER4GIAYflGSE IUxSrQXZWO5dqWd/ltlpd5PGbQn6WJa0SBnAHspiOsOUb0gyVHLureYcK3qgxfX1nL0I x2RSdtHvwCDOaFVatodSruMRadl1tLFRwbdYMNQAwzffZkY4421qCh7Yx5otBV/kg22J 7Fa24kO35aKKczFHcK+R5wGgc2yafAxAqIOky/XpcWVq6bYc/8j7u79lRzeMmPUVvDoq SAoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vfbjbC5RBOvZEvrCux1NjNQX2php0gkjjfHnzp35t4c=; b=a+Ydqu9NW+O1Vd3YvRtrdtzAEM0lTt8Ov7r6eWrtnpUQ5hqBH8ZezVDhWbUgEmA4rZ E4CP8X5xQm3bpzlpjSftaFxtmrIkKxeHiQxaGHIj48Vvv9+vM8w5xQVjjDHMHRYZqK1O bdAKm9d7AiJs0fS6qILQ8egJagr+4w9jBq4FMPGVJWhXjXdDXHDrOw7JAQXOR1kitxJh Q777j6UvgJBDgx7N9GFYqqJjNPp+zi0mehFBf66IvA0lvCMzoLHoh8foiJgyfunfTs5l mBcDvG/yNWwsgmamkRiLeUE9cqCzHIq0qt4DUL9znXOBFeSNFvvnUwDLUapmL4+Cb7iN n31w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=akNnW5dU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bz6si17852412ejc.374.2021.09.20.11.57.55; Mon, 20 Sep 2021 11:58:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=akNnW5dU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349698AbhITS5k (ORCPT + 99 others); Mon, 20 Sep 2021 14:57:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:37162 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385804AbhITSw2 (ORCPT ); Mon, 20 Sep 2021 14:52:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5DA6A615E5; Mon, 20 Sep 2021 17:45:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632159904; bh=eizUbIsjMYN+/U7qxJUDeZOmJ6obtyGbGnTfTb7yHFk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=akNnW5dU4Cx5qLoSXfsKOMMVVZHBfSw64ojyQUwciY/dbVxov5yQqNih9bqJdF4sa LU9LFjLIT4Q1oI+XF35+yLZ6UmeLvIzrNj4LCoWOrP6/EOgIV6QTx5JYWNDoDuEjYP P5SO7qDo/YRjufnMVhVtVYEUgSdSTIHCJYFkczGFb9EWUiTgAxlSllv50sLaS6HbXw Lf6MX2irdcNOS6dpDMa5uzOoBZVApoH5wvi68MRjYgnfbw1J2LKF/QG8yPm7ebFvWt XlY0ir1kbMIhX5qvxdMOPvg6jsZkfKYK+d7gMwixJ/l4PwQpGkCizDzOsZmVmJM9Pi vVbkpcIfjuhsg== Date: Mon, 20 Sep 2021 10:45:03 -0700 From: Mark Gross To: Arnd Bergmann Cc: Matan Ziv-Av , Hans de Goede , Mark Gross , Arnd Bergmann , "Rafael J. Wysocki" , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] platform/x86: lg-laptop: Fix possible NULL pointer derefence Message-ID: References: <20210920095556.1175269-1-arnd@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210920095556.1175269-1-arnd@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 20, 2021 at 11:55:50AM +0200, Arnd Bergmann wrote: > From: Arnd Bergmann > > 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 > --- > 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) seems appropriate. --mark > switch (product[4]) { > case '5': > case '6': > -- > 2.29.2 >