From patchwork Thu Apr 20 02:25:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Darren Hart X-Patchwork-Id: 9689275 X-Patchwork-Delegate: dvhart@infradead.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A97A6602C9 for ; Thu, 20 Apr 2017 02:27:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9C2BE203C0 for ; Thu, 20 Apr 2017 02:27:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9145F25404; Thu, 20 Apr 2017 02:27:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32FD3203C0 for ; Thu, 20 Apr 2017 02:27:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966596AbdDTC0V (ORCPT ); Wed, 19 Apr 2017 22:26:21 -0400 Received: from bombadil.infradead.org ([65.50.211.133]:59451 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966030AbdDTC0U (ORCPT ); Wed, 19 Apr 2017 22:26:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=/vENzPkR+TZ3iLCNaBWU4TFDwxQs2w8jv78fwqPRznE=; b=SOu9u99anLg2KHIqp6nxJG1vh piNPEVUDyWMP8TQKjd2jYFGfJRUYJjJ9Xz6T34Rp2JyyZKbu8RubNVY572euk37nLyFsk8axryiD6 3qfvJnDBAsTExvpsMoyJXEfo5a7vZY9Qe+DUtCAkYlpvhwwdAEW4408mevUWBprK29QqUTfFBNQmt 8opobxKCJxkpeoBTzdaqHiqjTkdTiFTb1OEenlLry9ythbWV0suHDxAFDMMXrD8u29kwhJWTX/F1x 2VrO6tJHLu5fY2vHOopPvfe3nYmPRBbXUKC0hMjDxOYdZ3uojSkD8VWNZsv0e44nLOX9Ham+iZ7sF Eg/7Z348Q==; Received: from dvhart by bombadil.infradead.org with local (Exim 4.87 #1 (Red Hat Linux)) id 1d11nX-0005G4-Kj; Thu, 20 Apr 2017 02:26:19 +0000 From: Darren Hart To: dvhart@infradead.org Cc: andy@infradead.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, carlo@caione.org Subject: [PATCH 4/9] platform/x86: hp-wmi: Refactor redundant HPWMI_READ functions Date: Wed, 19 Apr 2017 19:25:16 -0700 Message-Id: <1dd50801a0dbb8bd6ec1411b5c644a01a35b0136.1492654448.git.dvhart@infradead.org> X-Mailer: git-send-email 2.9.3 In-Reply-To: References: In-Reply-To: References: Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Darren Hart (VMware)" Several functions perform the same WMI read int with different query arguments. Refactor this into a single hp_wmi_read_int function. Signed-off-by: Darren Hart (VMware) --- drivers/platform/x86/hp-wmi.c | 82 +++++++++++++------------------------------ 1 file changed, 24 insertions(+), 58 deletions(-) diff --git a/drivers/platform/x86/hp-wmi.c b/drivers/platform/x86/hp-wmi.c index 60d1e4c..758c229 100644 --- a/drivers/platform/x86/hp-wmi.c +++ b/drivers/platform/x86/hp-wmi.c @@ -252,55 +252,35 @@ static int hp_wmi_perform_query(int query, int write, void *buffer, return 0; } -static int hp_wmi_display_state(void) +static int hp_wmi_read_int(int query) { - int state = 0; - int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, HPWMI_READ, &state, - sizeof(state), sizeof(state)); - if (ret) - return ret < 0 ? ret : -EINVAL; - return state; -} + int val = 0, ret; -static int hp_wmi_hddtemp_state(void) -{ - int state = 0; - int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, HPWMI_READ, &state, - sizeof(state), sizeof(state)); - if (ret) - return ret < 0 ? ret : -EINVAL; - return state; -} + ret = hp_wmi_perform_query(query, HPWMI_READ, &val, + sizeof(val), sizeof(val)); -static int hp_wmi_als_state(void) -{ - int state = 0; - int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, HPWMI_READ, &state, - sizeof(state), sizeof(state)); if (ret) return ret < 0 ? ret : -EINVAL; - return state; + + return val; } static int hp_wmi_dock_state(void) { - int state = 0; - int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, HPWMI_READ, &state, - sizeof(state), sizeof(state)); + int state = hp_wmi_read_int(HPWMI_HARDWARE_QUERY); - if (ret) - return ret < 0 ? ret : -EINVAL; + if (state < 0) + return state; return state & 0x1; } static int hp_wmi_tablet_state(void) { - int state = 0; - int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, HPWMI_READ, &state, - sizeof(state), sizeof(state)); - if (ret) - return ret < 0 ? ret : -EINVAL; + int state = hp_wmi_read_int(HPWMI_HARDWARE_QUERY); + + if (state < 0) + return state; return (state & 0x4) ? 1 : 0; } @@ -430,20 +410,10 @@ static int hp_wmi_rfkill2_refresh(void) return 0; } -static int hp_wmi_post_code_state(void) -{ - int state = 0; - int ret = hp_wmi_perform_query(HPWMI_POSTCODEERROR_QUERY, HPWMI_READ, &state, - sizeof(state), sizeof(state)); - if (ret) - return ret < 0 ? ret : -EINVAL; - return state; -} - static ssize_t show_display(struct device *dev, struct device_attribute *attr, char *buf) { - int value = hp_wmi_display_state(); + int value = hp_wmi_read_int(HPWMI_DISPLAY_QUERY); if (value < 0) return -EINVAL; return sprintf(buf, "%d\n", value); @@ -452,7 +422,7 @@ static ssize_t show_display(struct device *dev, struct device_attribute *attr, static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr, char *buf) { - int value = hp_wmi_hddtemp_state(); + int value = hp_wmi_read_int(HPWMI_HDDTEMP_QUERY); if (value < 0) return -EINVAL; return sprintf(buf, "%d\n", value); @@ -461,7 +431,7 @@ static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr, static ssize_t show_als(struct device *dev, struct device_attribute *attr, char *buf) { - int value = hp_wmi_als_state(); + int value = hp_wmi_read_int(HPWMI_ALS_QUERY); if (value < 0) return -EINVAL; return sprintf(buf, "%d\n", value); @@ -489,7 +459,7 @@ static ssize_t show_postcode(struct device *dev, struct device_attribute *attr, char *buf) { /* Get the POST error code of previous boot failure. */ - int value = hp_wmi_post_code_state(); + int value = hp_wmi_read_int(HPWMI_POSTCODEERROR_QUERY); if (value < 0) return -EINVAL; return sprintf(buf, "0x%x\n", value); @@ -540,9 +510,9 @@ static void hp_wmi_notify(u32 value, void *context) struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; u32 event_id, event_data; union acpi_object *obj; - int key_code = 0, ret; acpi_status status; u32 *location; + int key_code; status = wmi_get_event_data(value, &response); if (status != AE_OK) { @@ -593,11 +563,8 @@ static void hp_wmi_notify(u32 value, void *context) case HPWMI_SMART_ADAPTER: break; case HPWMI_BEZEL_BUTTON: - ret = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, HPWMI_READ, - &key_code, - sizeof(key_code), - sizeof(key_code)); - if (ret) + key_code = hp_wmi_read_int(HPWMI_HOTKEY_QUERY); + if (key_code < 0) break; if (!sparse_keymap_report_event(hp_wmi_input_dev, @@ -726,12 +693,11 @@ static void cleanup_sysfs(struct platform_device *device) static int __init hp_wmi_rfkill_setup(struct platform_device *device) { - int err, wireless = 0; + int err, wireless; - err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, HPWMI_READ, &wireless, - sizeof(wireless), sizeof(wireless)); - if (err) - return err; + wireless = hp_wmi_read_int(HPWMI_WIRELESS_QUERY); + if (wireless) + return wireless; err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, HPWMI_WRITE, &wireless, sizeof(wireless), 0);