From patchwork Wed Nov 29 08:13:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haoran Liu X-Patchwork-Id: 748137 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="eaodECY4" Received: from m12.mail.163.com (m12.mail.163.com [220.181.12.198]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 42E811735; Wed, 29 Nov 2023 00:14:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=9p8e0KY2P60TNVeST4 fjoopvIyST862pP3T8NJI8fMA=; b=eaodECY4Mt7e77h+Zo94XNCN7+q6VqF0ci SRONFmPvJg2zqOZwFztTQVlSGtdiwp8TqZaVjympV7Lsp91xGUeybJeOWDA9OZ0g tpXopoMmpxODZXx482ufhh3s+eGm78HE9tcb1hMshY1+ssDA28rEwzL4kA15YU1r c/zCoapTY= Received: from localhost.localdomain (unknown [39.144.190.126]) by zwqz-smtp-mta-g3-2 (Coremail) with SMTP id _____wD3H0zE8mZln_DuEA--.38488S2; Wed, 29 Nov 2023 16:13:57 +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] fan_core: Add error handling for acpi_driver_data Date: Wed, 29 Nov 2023 00:13:55 -0800 Message-Id: <20231129081355.32317-1-liuhaoran14@163.com> X-Mailer: git-send-email 2.17.1 X-CM-TRANSID: _____wD3H0zE8mZln_DuEA--.38488S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7ur4kAFyxCF13Zw18GFWxJFb_yoW8XF4UpF W3KFy5ArWqgr47Ww4UCa1rZFW3X3Z5Z34I9FWkA345Wa15Kr98uFyxGa4jv34YyF4xKan2 vrykJFyDCF1DZrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zEBTYUUUUUU= X-CM-SenderInfo: xolxxtxrud0iqu6rljoofrz/xtbBcgQ3gletj45lSAAAsV Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: This patch introduces error handling for the acpi_driver_data call in function acpi_fan_get_fif and acpi_fan_get_fps, within drivers/acpi/fan_core.c. Previously, there was no check for a null return from acpi_driver_data, which could lead to potential instability in scenarios where acpi_driver_data fails. Signed-off-by: Haoran Liu --- drivers/acpi/fan_core.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c index 9dccbae9e8ea..f3228fb9c90f 100644 --- a/drivers/acpi/fan_core.c +++ b/drivers/acpi/fan_core.c @@ -215,6 +215,13 @@ static int acpi_fan_get_fif(struct acpi_device *device) { struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; struct acpi_fan *fan = acpi_driver_data(device); + + if (!fan) { + dev_err(&device->dev, "No ACPI fan data associated " + "with the device\n"); + return -EINVAL; + } + struct acpi_buffer format = { sizeof("NNNN"), "NNNN" }; u64 fields[4]; struct acpi_buffer fif = { sizeof(fields), fields }; @@ -265,6 +272,12 @@ static int acpi_fan_speed_cmp(const void *a, const void *b) static int acpi_fan_get_fps(struct acpi_device *device) { struct acpi_fan *fan = acpi_driver_data(device); + + if (!fan) { + dev_err(&device->dev, "Failed to retrieve ACPI fan data\n"); + return -ENODEV; + } + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; union acpi_object *obj; acpi_status status;