Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1228661rdb; Wed, 6 Dec 2023 12:11:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFqZg/d0EAhdluWEPMEGtqztC7+oocs8cx0GTYa7dPnGXDg30RHcQe2C3Tqr1VdE/VGcxBb X-Received: by 2002:a05:6a20:1586:b0:188:28e:5a75 with SMTP id h6-20020a056a20158600b00188028e5a75mr1419093pzj.5.1701893495957; Wed, 06 Dec 2023 12:11:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701893495; cv=none; d=google.com; s=arc-20160816; b=Sme5Xqdd9bauD188Pzna7+0VTFuORdI7VtyJBAFhjdA2LaldReWdv0GtDX1x6C9avi I4JlJKYtAR3YGihNrjg8794MBsIID+g3q+rMUVOPNpI0/E7frHMKeGzaLPzQoRnGOFbH OI30dTw4M9OFSRnVfuXdsa6/8KEFQlr56EvXqCEthR/bDrpbhEifJZlsP9S/TyyHvlb9 KrFIk97MEO4GxGc2t4XYuYjacQUO9cKqqkjOF7THxnAAnaXyn3HoKKSOfdwJs6o/ggT5 K8cFlinLm9m/J92gKkmb+VdW0aak0J/b/vmTcUNvoh5ZXXgK6HQyRoR9XIyFhV63r2xq g84A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=oQlDejwQ1mhCUMk/NZFi01yiEaDvWHYpglAJFdrAYU8=; fh=pP7xEwgFwbyix4Is31v98uewMB6yWmFz9f1+OM+/0ug=; b=YC5hoa6ytcaxoIhKsM2Nys1hhVUlwj9ZmQE797fNYPmamPtsoRTfrqJBJavmiC+IaJ LfGUxc042QsECTPGhXtipoHu9vgykGz/ZiyZT/xZisVULCutG/uiMI+YarTt4CyQLdyx k8DRylCo4L3EDOfJ9cgQkhNfBqWD8TYt8k0YK21XdfYR8JmSEWMrHbkF57TETr5wAmJw ZAHU+3bOaP44i4GX+OMBv5j6N2yuR4fT2msnpoxXMiAncPrqKilkbocYyYrPUVIXp1Jv Sag/x2pBOT71JqDfzp+cZR2D1jJnzJL+IkSGAXRnGYSlb1Nh8Dn9u3Zz9hI3BW/txZWT 1TLg== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id fc12-20020a056a002e0c00b006cb686c08f4si456012pfb.211.2023.12.06.12.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 12:11:35 -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; 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=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id DCA3C809B9C3; Wed, 6 Dec 2023 12:11:06 -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 S1379520AbjLFUKx convert rfc822-to-8bit (ORCPT + 99 others); Wed, 6 Dec 2023 15:10:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442877AbjLFUKv (ORCPT ); Wed, 6 Dec 2023 15:10:51 -0500 Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7048311F; Wed, 6 Dec 2023 12:10:57 -0800 (PST) Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-1fb00ea5e5fso32417fac.1; Wed, 06 Dec 2023 12:10:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701893457; x=1702498257; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=32NboKdEEry+p7HRVVx+YEW6Zjud8R5v5yW1kUM2NMU=; b=sKlJBRc++kmYVjtJBIMsWf2mFcme5f1AiYWDvJP0v1AzxUkBuYdwa/e/h/sZotFAil Blwf0bWPbZANUmLAk8tqY37x2z/COhp2R8n2elh5DTSx9yd3YgHjvHumlee9wel2fiIU 6lpZ9ItDeFHqwZQPVT/njkNAQQSA0obiDvnx8HYT6GoEDB65UhZwLFbkR5Lkm2GyiQ/V +PAnONmshaUGDb4ORJPVHWl9uAIemhAjUFmkk/FGyjE/f1h+X3ZkyvPb0KhF8jDscBBW XNj2FwDf6qqwNPI8Opc44YDvObCzOhzBytj9kUANcwnkKHU/1L5x+FkdjTnlfAI+EnDg OenQ== X-Gm-Message-State: AOJu0YxyY4WrPsFOvwgqpeoSG5T0QwHVanVw9fzTc3bWQTOd2MWg3nXs R5ZIiU6SgqDAv5Zj1z1NrFwNQLy0GiSxuMradeo= X-Received: by 2002:a05:6870:9e84:b0:1fa:f195:e3b4 with SMTP id pu4-20020a0568709e8400b001faf195e3b4mr3000102oab.2.1701893456740; Wed, 06 Dec 2023 12:10:56 -0800 (PST) MIME-Version: 1.0 References: <20231129084247.32443-1-liuhaoran14@163.com> In-Reply-To: <20231129084247.32443-1-liuhaoran14@163.com> From: "Rafael J. Wysocki" Date: Wed, 6 Dec 2023 21:10:46 +0100 Message-ID: Subject: Re: [PATCH] [ACPI] sbshc: Add error handling for acpi_driver_data To: Haoran Liu Cc: rafael@kernel.org, lenb@kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=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, 06 Dec 2023 12:11:07 -0800 (PST) On Wed, Nov 29, 2023 at 9:43 AM Haoran Liu wrote: > > 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. This needs to describe a real scenario in which acpi_driver_data() can return NULL for each of the 2 places modified by the patch. > 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 >