From patchwork Wed Feb 3 21:55:43 2021 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: 12065445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62282C433DB for ; Wed, 3 Feb 2021 21:56:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2041064E46 for ; Wed, 3 Feb 2021 21:56:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232297AbhBCV4f (ORCPT ); Wed, 3 Feb 2021 16:56:35 -0500 Received: from mail-40136.protonmail.ch ([185.70.40.136]:48927 "EHLO mail-40136.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232324AbhBCV4a (ORCPT ); Wed, 3 Feb 2021 16:56:30 -0500 Date: Wed, 03 Feb 2021 21:55:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1612389346; bh=GhcHBs8j0uBYIt/Z2xUQNs7vDHmcB0oah9z/slNJzN0=; h=Date:To:From:Reply-To:Subject:From; b=vecFyt4NwN/6WtPiRDo9/wrvlx9hsxXE8JY5Xn5NpXjRKRUC0YuA+DcAi7K+tbghy X7fq6v3v4QJFqY429bjo5iQNYi4QW8Nso0a4ff/+dYNaNJoj+BwZ6JrjDWGwge/XQc nvKZe9eG9CrMWxrqa/f8g654WYUH2bX7sKPgjvC8= To: platform-driver-x86@vger.kernel.org, Hans de Goede , Mark Gross , Ike Panhc , Andy Shevchenko From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Reply-To: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= Subject: [PATCH v3 13/29] platform/x86: ideapad-laptop: convert ACPI helpers to return -EIO in case of failure Message-ID: <20210203215403.290792-14-pobrn@protonmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org ACPI helpers returned -1 in case of failure. Convert these functions to return appropriate error codes, and convert their users to propagate these error codes accordingly. Signed-off-by: Barnabás Pőcze diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c index ba0bd344f5ed..7815ec93f546 100644 --- a/drivers/platform/x86/ideapad-laptop.c +++ b/drivers/platform/x86/ideapad-laptop.c @@ -127,7 +127,7 @@ static int read_method_int(acpi_handle handle, const char *method, int *val) status = acpi_evaluate_integer(handle, (char *)method, NULL, &result); if (ACPI_FAILURE(status)) { *val = -1; - return -1; + return -EIO; } *val = result; return 0; @@ -148,7 +148,7 @@ static int method_int1(acpi_handle handle, char *method, int cmd) acpi_status status; status = acpi_execute_simple_method(handle, method, cmd); - return ACPI_FAILURE(status) ? -1 : 0; + return ACPI_FAILURE(status) ? -EIO : 0; } static int method_dytc(acpi_handle handle, int cmd, int *ret) @@ -167,7 +167,7 @@ static int method_dytc(acpi_handle handle, int cmd, int *ret) if (ACPI_FAILURE(status)) { *ret = -1; - return -1; + return -EIO; } *ret = result; return 0; @@ -189,7 +189,7 @@ static int method_vpcr(acpi_handle handle, int cmd, int *ret) if (ACPI_FAILURE(status)) { *ret = -1; - return -1; + return -EIO; } *ret = result; return 0; @@ -211,56 +211,62 @@ static int method_vpcw(acpi_handle handle, int cmd, int data) status = acpi_evaluate_object(handle, "VPCW", ¶ms, NULL); if (status != AE_OK) - return -1; + return -EIO; return 0; } static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data) { - int val; unsigned long int end_jiffies; + int val, err; - if (method_vpcw(handle, 1, cmd)) - return -1; + err = method_vpcw(handle, 1, cmd); + if (err) + return err; end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; while (time_before(jiffies, end_jiffies)) { schedule(); - if (method_vpcr(handle, 1, &val)) - return -1; + err = method_vpcr(handle, 1, &val); + if (err) + return err; if (val == 0) { - if (method_vpcr(handle, 0, &val)) - return -1; + err = method_vpcr(handle, 0, &val); + if (err) + return err; *data = val; return 0; } } acpi_handle_err(handle, "timeout in %s\n", __func__); - return -1; + return -ETIMEDOUT; } static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data) { - int val; unsigned long int end_jiffies; + int val, err; - if (method_vpcw(handle, 0, data)) - return -1; - if (method_vpcw(handle, 1, cmd)) - return -1; + err = method_vpcw(handle, 0, data); + if (err) + return err; + err = method_vpcw(handle, 1, cmd); + if (err) + return err; end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1; while (time_before(jiffies, end_jiffies)) { schedule(); - if (method_vpcr(handle, 1, &val)) - return -1; + err = method_vpcr(handle, 1, &val); + if (err) + return err; if (val == 0) return 0; } acpi_handle_err(handle, "timeout in %s\n", __func__); - return -1; + return -ETIMEDOUT; } /* @@ -395,8 +401,8 @@ static ssize_t store_ideapad_cam(struct device *dev, if (sscanf(buf, "%i", &state) != 1) return -EINVAL; ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_CAMERA, state); - if (ret < 0) - return -EIO; + if (ret) + return ret; return count; } @@ -428,8 +434,8 @@ static ssize_t store_ideapad_fan(struct device *dev, if (state < 0 || state > 4 || state == 3) return -EINVAL; ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_FAN, state); - if (ret < 0) - return -EIO; + if (ret) + return ret; return count; } @@ -461,8 +467,8 @@ static ssize_t __maybe_unused touchpad_store(struct device *dev, return ret; ret = write_ec_cmd(priv->adev->handle, VPCCMD_W_TOUCHPAD, state); - if (ret < 0) - return -EIO; + if (ret) + return ret; return count; } @@ -495,8 +501,8 @@ static ssize_t conservation_mode_store(struct device *dev, ret = method_int1(priv->adev->handle, "SBMC", state ? BMCMD_CONSERVATION_ON : BMCMD_CONSERVATION_OFF); - if (ret < 0) - return -EIO; + if (ret) + return ret; return count; } @@ -533,8 +539,8 @@ static ssize_t fn_lock_store(struct device *dev, ret = method_int1(priv->adev->handle, "SALS", state ? HACMD_FNLOCK_ON : HACMD_FNLOCK_OFF); - if (ret < 0) - return -EIO; + if (ret) + return ret; return count; } @@ -1025,7 +1031,8 @@ static void ideapad_check_special_buttons(struct ideapad_private *priv) { unsigned long bit, value; - read_ec_data(priv->adev->handle, VPCCMD_R_SPECIAL_BUTTONS, &value); + if (read_ec_data(priv->adev->handle, VPCCMD_R_SPECIAL_BUTTONS, &value)) + return; for_each_set_bit (bit, &value, 16) { switch (bit) { @@ -1053,22 +1060,27 @@ static int ideapad_backlight_get_brightness(struct backlight_device *blightdev) { struct ideapad_private *priv = bl_get_data(blightdev); unsigned long now; + int err; - if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now)) - return -EIO; + err = read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now); + if (err) + return err; return now; } static int ideapad_backlight_update_status(struct backlight_device *blightdev) { struct ideapad_private *priv = bl_get_data(blightdev); + int err; - if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL, - blightdev->props.brightness)) - return -EIO; - if (write_ec_cmd(priv->adev->handle, VPCCMD_W_BL_POWER, - blightdev->props.power == FB_BLANK_POWERDOWN ? 0 : 1)) - return -EIO; + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_BL, + blightdev->props.brightness); + if (err) + return err; + err = write_ec_cmd(priv->adev->handle, VPCCMD_W_BL_POWER, + blightdev->props.power != FB_BLANK_POWERDOWN); + if (err) + return err; return 0; } @@ -1083,13 +1095,17 @@ static int ideapad_backlight_init(struct ideapad_private *priv) struct backlight_device *blightdev; struct backlight_properties props; unsigned long max, now, power; + int err; - if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &max)) - return -EIO; - if (read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now)) - return -EIO; - if (read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power)) - return -EIO; + err = read_ec_data(priv->adev->handle, VPCCMD_R_BL_MAX, &max); + if (err) + return err; + err = read_ec_data(priv->adev->handle, VPCCMD_R_BL, &now); + if (err) + return err; + err = read_ec_data(priv->adev->handle, VPCCMD_R_BL_POWER, &power); + if (err) + return err; memset(&props, 0, sizeof(struct backlight_properties)); props.max_brightness = max;