Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1865966pxb; Mon, 20 Sep 2021 07:07:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwg8wV303ofbBB4EyMLeFZU2FOhvLpCV8yCPP65ssYyG7tRStY8k173j8Qkyw8Zb2FRTIVS X-Received: by 2002:a05:6638:130f:: with SMTP id r15mr6552513jad.141.1632146858526; Mon, 20 Sep 2021 07:07:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632146858; cv=none; d=google.com; s=arc-20160816; b=pAwomq8zXbjB8iN3yR9/dI7K31a81rttOpZEsEz8DXljtYg4Gp4YpBlmDabuScyv3m a5vCP43EtepVfNJYqfk4l5DOS26lTxGgNn7JFwLs/zaJnTvKl6AbGJ8LgWrGfpLmPaPJ MjjWAMSoTzDasYao37NoEODwpfcMpnGn5xLkzpGcvYkk0nYfjVtI8dbKspTR/VufHohn AYRpg3ix2jLRaJvUcvW0FS/DDo2TfnCIVN1bpsmVp7NCOM9h0v4NnFTH/q3xDYYKD6Gb NgcD+UeWgdlqZ76bfSNugNq0P8eDgGFNK8ZIk4futEuICzCaokOX3JMBWK+OFSPiflg0 OjGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=MP24pMxpM8fO0FWqlKM9e1yJRXZYVcXyKknFjgBUU4w=; b=xYMPvS71XbgMIX4mEIQryEv9l9ennlmQDPXWOERAAUEnXwwgOEsZLg+1eCvYqpsvlv SZpPOvyYg6Hmp/LL+OihJzRnk5uLtT3Dqd/fdpuGZQsPxmb/pJnkKHqu8NbowQ3lqzsO 3mAieED21emFRCFV15vcZl50YGo5Lj3obczI7Z4RVJ6aDk9DRNGTBLMaURoPPPHmVmka 3x8fm3WtbZvhV4L6hl2ZDP/AQmzn/xlLHcIYJsp3GNe/sJy52oMc2sN6QX8UEGJM8eq+ hSdxc6qSLuLv2ctpP9Y0D/f975E3iW4tDb6fJn+sYw23rqVDXHftFIxWe7Uvx3T42VTQ 4RUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jK5eEfPF; 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 z10si12323629ioe.51.2021.09.20.07.07.13; Mon, 20 Sep 2021 07:07:38 -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=jK5eEfPF; 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 S230503AbhITJ53 (ORCPT + 99 others); Mon, 20 Sep 2021 05:57:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:40382 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233136AbhITJ52 (ORCPT ); Mon, 20 Sep 2021 05:57:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5E51160240; Mon, 20 Sep 2021 09:56:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632131761; bh=UMgc0ypSsQxjI//9tTpmdJQMwxV+y+7dPPyn1NAloNQ=; h=From:To:Cc:Subject:Date:From; b=jK5eEfPFq9arxUMS+0gscszPEiPaDBA6twyL8kDnYc5Nxd57Mt0FdjhPXcZbE7Rwj Cg4ZTFD6fTKdyraik9XBQzb/cSIn8bWpGELrN1QzR2bmN0cRK1Ru5Z7+9RQutAC40q zJwdMfk9t9ziQp00qFb8Ym+2Uu5lfu4XtY7zc1mZpnW+/9CjYhYJ4cdJx9LH/j4N3x Bgl8mHtcy04LpRWoYTfrecgm75nasY2Tb+VlMsgl1B4K26BHkMfDDicVkz+chA1Mk8 XyY4upQjn1arnPDtuUDlEaTyHez8J1gWMxqM1DXjYUypSY+e1uYaf9hxlXWHYuknRe j4H8N/Ka4oEHg== From: Arnd Bergmann To: Matan Ziv-Av , Hans de Goede , Mark Gross Cc: Arnd Bergmann , "Rafael J. Wysocki" , 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 Message-Id: <20210920095556.1175269-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) switch (product[4]) { case '5': case '6': -- 2.29.2