From patchwork Wed Oct 5 15:00:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 12999340 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12DE0C433FE for ; Wed, 5 Oct 2022 15:02:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230349AbiJEPCm (ORCPT ); Wed, 5 Oct 2022 11:02:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230350AbiJEPC0 (ORCPT ); Wed, 5 Oct 2022 11:02:26 -0400 Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7488F4C for ; Wed, 5 Oct 2022 08:00:50 -0700 (PDT) Date: Wed, 05 Oct 2022 15:00:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1664982046; x=1665241246; bh=GhFgu78eZ2flpdK/5tVb3/Qc4v0aQzigC4qbE4KAuak=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID; b=kNjQ0+5oQE2PMR2Q8JXsLn8teUJ5zdEHPzbdv8Zov2vKOlaeGlu+KfEHJqEmQhXj2 RwUZQDRjTpJW008y3GdEjOq/mTMKGxnqVAnxtb+S/aBcjhYwb3nA8DFXEP5Zj/heub G+WHfy7DedUBjaBVlf3/hZx7L6PXZSU/Yhn792rf3LzE8tfq15S6LzfFeM86JsyA/S 0dxC5e7ln09plBuxHkBflYOCsLKQNqa5wCkgLHLhWhjxMck4Qvi3qBBwu+2XfxEQcI PyBBbbhIOhzobvywkfAALeFeaDipvYjM1CC3jUZ3yH9n9sxAIBjjIU5wQaTrFPj3iG UGFYawWyUjNdw== To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ayman Bagabas From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v1 1/3] platform/x86: huawei-wmi: do not hard-code sizes Message-ID: <20221005150032.173198-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Use `sizeof()` and `ARRAY_SIZE()` instead of hard-coding buffer sizes and indices. Signed-off-by: Barnabás Pőcze --- drivers/platform/x86/huawei-wmi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.38.0 diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index eac3e6b4ea11..66b53b90188f 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -323,12 +323,12 @@ static int huawei_wmi_battery_get(int *start, int *end) u8 ret[0x100]; int err, i; - err = huawei_wmi_cmd(BATTERY_THRESH_GET, ret, 0x100); + err = huawei_wmi_cmd(BATTERY_THRESH_GET, ret, sizeof(ret)); if (err) return err; /* Find the last two non-zero values. Return status is ignored. */ - i = 0xff; + i = ARRAY_SIZE(ret) - 1; do { if (start) *start = ret[i-1]; From patchwork Wed Oct 5 15:00:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 12999341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 938ABC433FE for ; Wed, 5 Oct 2022 15:03:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230384AbiJEPDE (ORCPT ); Wed, 5 Oct 2022 11:03:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230391AbiJEPCd (ORCPT ); Wed, 5 Oct 2022 11:02:33 -0400 Received: from mail-0301.mail-europe.com (mail-0301.mail-europe.com [188.165.51.139]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7300C7E308 for ; Wed, 5 Oct 2022 08:01:01 -0700 (PDT) Date: Wed, 05 Oct 2022 15:00:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1664982056; x=1665241256; bh=JL3CI8kcEZT9fAOo23SiVPEWL+vsQw4O37kMbsrp2Jc=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=KohWRHzkr6/LTske/gZFpovxuVpEP0Q9NazlbXLcOQH4hfC/n12JC8eWJLxNGeizw id5TbKSpxf72EAJNMIwqacrFSOzV3IC1fgs5z9T7A3enymv0TmFZCpja7xhN0nbAWv klB84EFR/UQC1G+8jUJEwwjldSaGK4LNiPnyo/1FLdEjolbTws9mshH6OTP/GejU/+ MVRvJN8dwUDKO9CGFS69/XrBwoRu+t1siRTMaAdCPKqPsAOpAgtoOhG8RDb2O6Kvx2 mIlsNDCJszsB+e1z1ZFrfEi2oPIoWTWaRGR/B445is2omwJGYjT5t1Aw+RkaRJtZUC Fxr1UxWVJZGUA== To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ayman Bagabas From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v1 2/3] platform/x86: huawei-wmi: fix return value calculation Message-ID: <20221005150032.173198-2-pobrn@protonmail.com> In-Reply-To: <20221005150032.173198-1-pobrn@protonmail.com> References: <20221005150032.173198-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org Previously, `huawei_wmi_input_setup()` returned the result of logical or-ing the return values of two functions that return negative errno-style error codes and one that returns `acpi_status`. If this returned value was non-zero, then it was propagated from the platform driver's probe function. That function should return a negative errno-style error code, so the result of the logical or that `huawei_wmi_input_setup()` returned was not appropriate. Fix that by checking each function separately and returning the error code unmodified. Fixes: 1ac9abeb2e5bf9 ("platform/x86: huawei-wmi: Move to platform driver") Signed-off-by: Barnabás Pőcze --- drivers/platform/x86/huawei-wmi.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) -- 2.38.0 diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index 66b53b90188f..bbab73c430d1 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -760,6 +760,9 @@ static int huawei_wmi_input_setup(struct device *dev, const char *guid, struct input_dev **idev) { + acpi_status status; + int err; + *idev = devm_input_allocate_device(dev); if (!*idev) return -ENOMEM; @@ -769,10 +772,19 @@ static int huawei_wmi_input_setup(struct device *dev, (*idev)->id.bustype = BUS_HOST; (*idev)->dev.parent = dev; - return sparse_keymap_setup(*idev, huawei_wmi_keymap, NULL) || - input_register_device(*idev) || - wmi_install_notify_handler(guid, huawei_wmi_input_notify, - *idev); + err = sparse_keymap_setup(*idev, huawei_wmi_keymap, NULL); + if (err) + return err; + + err = input_register_device(*idev); + if (err) + return err; + + status = wmi_install_notify_handler(guid, huawei_wmi_input_notify, *idev); + if (ACPI_FAILURE(status)) + return -EIO; + + return 0; } static void huawei_wmi_input_exit(struct device *dev, const char *guid) From patchwork Wed Oct 5 15:00:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= X-Patchwork-Id: 12999342 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCC3BC433FE for ; Wed, 5 Oct 2022 15:03:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230398AbiJEPDH (ORCPT ); Wed, 5 Oct 2022 11:03:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230215AbiJEPCf (ORCPT ); Wed, 5 Oct 2022 11:02:35 -0400 Received: from mail-0201.mail-europe.com (mail-0201.mail-europe.com [51.77.79.158]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ACD07E809 for ; Wed, 5 Oct 2022 08:01:05 -0700 (PDT) Date: Wed, 05 Oct 2022 15:00:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1664982060; x=1665241260; bh=QFm7x27ASU9xbMs2L98Rq//HgRjY93gOtvZTaJHCNT4=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=N201fCGkRnOpBiihKToMKKKt5YLMd6ylHEAb8aARiUXLnbvyjo0RI/PBCXu2wvvt+ UV+3Oy4WZkDvzQdO/kTms8YFdN34+DwEocjYHeFqdkFzTNL8xVcqq+Gd4+wttEk8G7 B8iHQeMsyar8sKuDp/zwB/al8tHrqOUGX2KaT6HYV82xEH/dLY3NvOD/Hjkkp7UC+K plcRFDmlewgUC5yLLC6dqNO64aOtaU3UEsHCBrSPu9WMcMXMmqVi20I5IT/jTk5fA5 K+jwdFEfd58vTnfvtUeN//grrRifLCynmwGZrZdFfIA+G8TczDidHZ7ISV/WyEb1mq BpkCRPV2u/mnQ== To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ayman Bagabas From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v1 3/3] platform/x86: huawei-wmi: remove unnecessary member Message-ID: <20221005150032.173198-3-pobrn@protonmail.com> In-Reply-To: <20221005150032.173198-1-pobrn@protonmail.com> References: <20221005150032.173198-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org The `huawei_wmi::idev` array is not actually used by the driver, so remove it. The piece of code that - I believe - was supposed to fill the array is flawed, it did not actually set any of the values inside the array. This was most likely masked by the fact that the input devices are devm managed and that the only function that needs a reference to the input devices is `huawei_wmi_input_notify()`, however, that does not access the appropriate input device via the `huawei_wmi` object. Signed-off-by: Barnabás Pőcze --- drivers/platform/x86/huawei-wmi.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) -- 2.38.0 diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c index bbab73c430d1..1c8fa4f0d7be 100644 --- a/drivers/platform/x86/huawei-wmi.c +++ b/drivers/platform/x86/huawei-wmi.c @@ -63,7 +63,6 @@ struct huawei_wmi { bool fn_lock_available; struct huawei_wmi_debug debug; - struct input_dev *idev[2]; struct led_classdev cdev; struct device *dev; @@ -756,31 +755,30 @@ static void huawei_wmi_input_notify(u32 value, void *context) kfree(response.pointer); } -static int huawei_wmi_input_setup(struct device *dev, - const char *guid, - struct input_dev **idev) +static int huawei_wmi_input_setup(struct device *dev, const char *guid) { + struct input_dev *idev; acpi_status status; int err; - *idev = devm_input_allocate_device(dev); - if (!*idev) + idev = devm_input_allocate_device(dev); + if (!idev) return -ENOMEM; - (*idev)->name = "Huawei WMI hotkeys"; - (*idev)->phys = "wmi/input0"; - (*idev)->id.bustype = BUS_HOST; - (*idev)->dev.parent = dev; + idev->name = "Huawei WMI hotkeys"; + idev->phys = "wmi/input0"; + idev->id.bustype = BUS_HOST; + idev->dev.parent = dev; - err = sparse_keymap_setup(*idev, huawei_wmi_keymap, NULL); + err = sparse_keymap_setup(idev, huawei_wmi_keymap, NULL); if (err) return err; - err = input_register_device(*idev); + err = input_register_device(idev); if (err) return err; - status = wmi_install_notify_handler(guid, huawei_wmi_input_notify, *idev); + status = wmi_install_notify_handler(guid, huawei_wmi_input_notify, idev); if (ACPI_FAILURE(status)) return -EIO; @@ -809,17 +807,14 @@ static int huawei_wmi_probe(struct platform_device *pdev) huawei_wmi->dev = &pdev->dev; while (*guid->guid_string) { - struct input_dev *idev = *huawei_wmi->idev; - if (wmi_has_guid(guid->guid_string)) { - err = huawei_wmi_input_setup(&pdev->dev, guid->guid_string, &idev); + err = huawei_wmi_input_setup(&pdev->dev, guid->guid_string); if (err) { dev_err(&pdev->dev, "Failed to setup input on %s\n", guid->guid_string); return err; } } - idev++; guid++; }