Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4425054rdh; Wed, 29 Nov 2023 00:43:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqqEAcUAGEwAYKPguEG7Y2J0tJEAbZwnS4AAbJ4+5Z8WnTehX6SkzLctEf+3OfuSxgMPPU X-Received: by 2002:a17:903:234c:b0:1cf:cb27:3aa5 with SMTP id c12-20020a170903234c00b001cfcb273aa5mr12848666plh.5.1701247392454; Wed, 29 Nov 2023 00:43:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701247392; cv=none; d=google.com; s=arc-20160816; b=fhU4qWG/j6EuZ0vGzlxJThm+9sFSx2wRmJ6JlS2A03MXiPBeipuQnNezGU3Wfmr9dI ZYMeMgT0vfb3ziL2v65WoUwZDxpjmH+LmWGzehCd12IRNh8Va/G8rSJjSLH83vl1oYUF 07GFNofVd7n1t/1DEqGc4xMeB8+lIt5Wdt6rxyvaXmuHLDpRtb7PFB4fNcg2+GcJsFFr Frad55OkMJVAJc7cmbAiKhu1K1u2d+HlDjXf/a8w2vcruTOtUetOQIXoW0SychCX+jgy T4e5jIABFvNRzmKrEWOGFamnNV/5g/KOKkC7+iC98eQoMzJaVe80jolFqvWlQayt8RUZ n0QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=xpJTTKdHjlMBDZ7OqelLGxQdRARxit/bAj42fJtrMCk=; fh=y9rp03rildofNr42ZhMWsnV3DoUMqW+LE1415fsZ0dA=; b=h0pm52Igr/qT4zEg/tEZDujk8iEmMxgKCY/UiSqoEIKvJV/xEp/9Eu2R/Or34sZS+A sDPybUi03e6X8h5sxe1C84sSFsgN2zfahBL90exWzDZUPnwJxc2sniaYcqepcxjl4d9M a4Wzz5q8s9Pu0wuPBWXY74F4pRJ9qIuFk6iLUiTfg6JO+yYsjAIGUIIB08LTreLO1MmP krAvkTHLijR6zrUaAAS0PCl7s/iajY57nD6UzS7IWVyXK+tPoPTY96AgFXY7i7Ln7YpE SkpE2gMSTCCx5PRaz2aT9+S64IecSe2aOx1xHpoGw4mHaCXsslwxmdHhv5wMqDZlKl1O zZHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=h0sVgehh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id a14-20020a170902b58e00b001cfb52101e3si9110325pls.413.2023.11.29.00.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 00:43:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=h0sVgehh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 5A6B3805B2EB; Wed, 29 Nov 2023 00:43:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230046AbjK2Im4 (ORCPT + 99 others); Wed, 29 Nov 2023 03:42:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjK2Imz (ORCPT ); Wed, 29 Nov 2023 03:42:55 -0500 Received: from m15.mail.163.com (m15.mail.163.com [45.254.50.220]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 91DE8AF; Wed, 29 Nov 2023 00:43:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=xpJTTKdHjlMBDZ7Oqe lLGxQdRARxit/bAj42fJtrMCk=; b=h0sVgehhTNhFRzv849YRR8Xr9gsPP/wulp J+H8chFOrVTHNwTrKV52UA4Uy9OAFQ2v91g4+VWSh/BuCUvgp+E8Kd9FxPVg/ltC 0Rz4+WXuDl6TEuny97NhDrnlH+fLaGx5bABi+6s/QAs5e8I3KnrBx+tQUseLugoN aBKayErMM= Received: from localhost.localdomain (unknown [39.144.190.126]) by zwqz-smtp-mta-g0-4 (Coremail) with SMTP id _____wAH6_yJ+WZlBfKnAA--.15849S2; Wed, 29 Nov 2023 16:42:50 +0800 (CST) From: Haoran Liu To: rafael@kernel.org Cc: lenb@kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Haoran Liu Subject: [PATCH] [ACPI] sbshc: Add error handling for acpi_driver_data Date: Wed, 29 Nov 2023 00:42:47 -0800 Message-Id: <20231129084247.32443-1-liuhaoran14@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: _____wAH6_yJ+WZlBfKnAA--.15849S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxJr48ur13Aw47tF1fur4rXwb_yoW8Gry8pF ZFgry7C3y8Gr47Krn3CFsYvFy5ua1Iv3srKF4xG34fWa1Uury5u3sYya40ya4jkFWxGF4I vw1UJFyruF4DZ3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zEPl8UUUUUU= X-Originating-IP: [39.144.190.126] X-CM-SenderInfo: xolxxtxrud0iqu6rljoofrz/1tbiZQE3gl8ZaQm27gAAsv X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 29 Nov 2023 00:43:10 -0800 (PST) This patch enhances the acpi_smbus_hc_add and acpi_smbus_hc_remove functions in drivers/acpi/sbshc.c by adding error handling for the acpi_driver_data calls. Previously, these functions did not check the return value of acpi_driver_data, potentially leading to stability issues if the function failed and returned a null pointer. Signed-off-by: Haoran Liu --- drivers/acpi/sbshc.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c index 16f2daaa2c45..1394104d3894 100644 --- a/drivers/acpi/sbshc.c +++ b/drivers/acpi/sbshc.c @@ -267,6 +267,12 @@ static int acpi_smbus_hc_add(struct acpi_device *device) init_waitqueue_head(&hc->wait); hc->ec = acpi_driver_data(acpi_dev_parent(device)); + if (!hc->ec) { + pr_err("Failed to retrieve parent ACPI device data\n"); + kfree(hc); + return -ENODEV; + } + hc->offset = (val >> 8) & 0xff; hc->query_bit = val & 0xff; device->driver_data = hc; @@ -288,6 +294,11 @@ static void acpi_smbus_hc_remove(struct acpi_device *device) return; hc = acpi_driver_data(device); + if (!hc) { + pr_err("Failed to retrieve ACPI SMBus HC data\n"); + return; + } + acpi_ec_remove_query_handler(hc->ec, hc->query_bit); acpi_os_wait_events_complete(); kfree(hc); -- 2.17.1