Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp85984pxb; Tue, 10 Nov 2020 20:58:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzRxaX28bAD8byPXaSZGQNPFObISpDxZSp29rlZKPgyteEP3oMJ9MP8OXZ0TIRTikvzzhlE X-Received: by 2002:a17:906:3e91:: with SMTP id a17mr23057334ejj.82.1605070721149; Tue, 10 Nov 2020 20:58:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605070721; cv=none; d=google.com; s=arc-20160816; b=fwI8RTFgkaEf4cLJaGj1lVD5OZEMv9laEpjjQAGWOL/1IJqOlKkC/eX2Pd2SMju8wf VO6Q3HTlS6EqQyB1D7bUduWzw5uMHMu9aNXGmXY8P8surLVLGmj1CwWHz5jZ5O1jHIGt vF4YyMBnEf+oUcY9+iYCV75wijsOyavBZJHJ8gCJsJdlRw+78Es3haG/FOkcSGs12Ti8 ZXSf/Gdhg4tEGOkoHJuhgD+yKktG35TlNUc5rK7qbRh9VMN123qzs4iUeuvyqfIDKzix nDwy80qGj2Mxfu+0MzqlMr1bHC4WceZtfYUXtmkfMPlov37Y4xkStGrr3uJug+bYkPk2 iyxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:references:cc :to:from:subject:dkim-signature; bh=uj9dOXaGqSlTaU3pwgaPlMYQQG9P/JCDz5+gitB10gs=; b=tE1WSXLHIeNG5014wAV0fKitPDWOrQiJeCAF3KFvJL0HadTmIImRA2+/nex0PBtveS r6DP57oxBy5GYA2lQ1JkobEYF7gV/BlqLiAtECET4+8JGwHUnFqBCjErcx44Oc/VzbHJ TpOB9UdRQlcLlpPFbRrmVe9c88blv6qaTYZ3JqzdxkCk6veZAOZfyDav5dJSQnVJLOy3 doHoVKtMrD6345W4fDLg1bMO/RhzVnGlyLRgFpuu6dKJmcS0FkDU7kfseEQfFHAmkQs8 t5a0IGVPZ6CI3Kv4se2DshVH+1A6rfa3gmt5QJW9uwoWx2tf1k5yhhrOvVveibEWmGok vkiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fnarfbargle.com header.s=mail header.b=gsa+3+Xh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fnarfbargle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id pj13si535695ejb.224.2020.11.10.20.57.51; Tue, 10 Nov 2020 20:58:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@fnarfbargle.com header.s=mail header.b=gsa+3+Xh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fnarfbargle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725903AbgKKE4H (ORCPT + 99 others); Tue, 10 Nov 2020 23:56:07 -0500 Received: from ns3.fnarfbargle.com ([103.4.19.87]:54788 "EHLO ns3.fnarfbargle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbgKKE4H (ORCPT ); Tue, 10 Nov 2020 23:56:07 -0500 Received: from srv.home ([10.8.0.1] ident=heh21299) by ns3.fnarfbargle.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1kciAL-00044G-RX; Wed, 11 Nov 2020 12:55:29 +0800 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=fnarfbargle.com; s=mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:References:Cc:To:From:Subject; bh=uj9dOXaGqSlTaU3pwgaPlMYQQG9P/JCDz5+gitB10gs=; b=gsa+3+Xh4gn5QI7kpsST8wGYCx6SQz+PaQYItNr96oMhLw6DaifhukAmvH0voO6Yz1onwbJiG5t5MvudLYRdK5KB4uDzfqG09mUKngai6sI7XvAd9tHtqpRfnGDoxt90DEEQJo1sHjk8fNkPwWKqV+sihzWILYwkt1fsn0w2rIU=; Subject: [PATCH v1] applesmc: Cleanups on top of re-work comms From: Brad Campbell To: linux-hwmon@vger.kernel.org Cc: Arnd Bergmann , "linux-kernel@vger.kernel.org" , hns@goldelico.com, Guenter Roeck , Andreas Kemnade , Jean Delvare , Henrik Rydberg References: <20200930105442.3f642f6c@aktux> <20201006090226.4275c824@kemnade.info> <68467f1b-cea1-47ea-a4d4-8319214b072a@fnarfbargle.com> <20201104142057.62493c12@aktux> <2436afef-99c6-c352-936d-567bf553388c@fnarfbargle.com> <7a085650-2399-08c0-3c4d-6cd1fa28a365@roeck-us.net> <10027199-5d31-93e7-9bd8-7baaebff8b71@roeck-us.net> <70331f82-35a1-50bd-685d-0b06061dd213@fnarfbargle.com> <3c72ccc3-4de1-b5d0-423d-7b8c80991254@fnarfbargle.com> <6d071547-10ee-ca92-ec8b-4b5069d04501@bitmath.org> <8e117844-d62a-bcb1-398d-c59cc0d4b878@fnarfbargle.com> <9109d059-d9cb-7464-edba-3f42aa78ce92@bitmath.org> <5310c0ab-0f80-1f9e-8807-066223edae13@bitmath.org> <57057d07-d3a0-8713-8365-7b12ca222bae@fnarfbargle.com> Message-ID: <4ed933bd-9bb9-f09f-0e0c-d82893d7ac76@fnarfbargle.com> Date: Wed, 11 Nov 2020 15:55:31 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A few small cleanups on top of the comms changes for applesmc.c : send_byte() is always called with APPLESMC_CMD_PORT, so simplify. Remove redundant check from smc_sane(). Consolidate writing length with other setup parameters. Consolidate read and write error messages to a single statement each. Length and error consolidation suggested by Henrik Rydberg Signed-off-by: Brad Campbell Index: linux-stable/drivers/hwmon/applesmc.c =================================================================== --- linux-stable.orig/drivers/hwmon/applesmc.c +++ linux-stable/drivers/hwmon/applesmc.c @@ -176,7 +176,7 @@ static int wait_status(u8 val, u8 mask) /* send_byte - Write to SMC data port. Callers must hold applesmc_lock. */ -static int send_byte(u8 cmd, u16 port) +static int send_byte(u8 cmd) { int status; @@ -186,7 +186,7 @@ static int send_byte(u8 cmd, u16 port) status = wait_status(SMC_STATUS_BUSY, SMC_STATUS_BUSY); if (status) return status; - outb(cmd, port); + outb(cmd, APPLESMC_DATA_PORT); return 0; } @@ -219,10 +219,7 @@ static int smc_sane(void) ret = send_command(APPLESMC_READ_CMD); if (ret) return ret; - ret = wait_status(0, SMC_STATUS_BUSY); - if (!ret) - return ret; - return -EIO; + return wait_status(0, SMC_STATUS_BUSY); } static int send_argument(const char *key) @@ -230,7 +227,7 @@ static int send_argument(const char *key int i; for (i = 0; i < 4; i++) - if (send_byte(key[i], APPLESMC_DATA_PORT)) + if (send_byte(key[i])) return -EIO; return 0; } @@ -245,23 +242,14 @@ static int read_smc(u8 cmd, const char * if (ret) return ret; - if (send_command(cmd) || send_argument(key)) { - pr_warn("%.4s: read arg fail\n", key); - return -EIO; - } - - /* This has no effect on newer (2012) SMCs */ - if (send_byte(len, APPLESMC_DATA_PORT)) { - pr_warn("%.4s: read len fail\n", key); - return -EIO; - } + if (send_command(cmd) || send_argument(key) || send_byte(len)) + goto err; for (i = 0; i < len; i++) { if (wait_status(SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY, - SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY) < 0) { - pr_warn("%.4s: read data[%d] fail\n", key, i); - return -EIO; - } + SMC_STATUS_AWAITING_DATA | SMC_STATUS_BUSY)) + goto err; + buffer[i] = inb(APPLESMC_DATA_PORT); } @@ -277,6 +265,9 @@ static int read_smc(u8 cmd, const char * pr_warn("flushed %d bytes, last value is: %d\n", i, data); return wait_status(0, SMC_STATUS_BUSY); +err: + pr_warn("read cmd fail: %x %.4s %d\n", cmd, key, len); + return -EIO; } static int write_smc(u8 cmd, const char *key, const u8 *buffer, u8 len) @@ -288,24 +279,17 @@ static int write_smc(u8 cmd, const char if (ret) return ret; - if (send_command(cmd) || send_argument(key)) { - pr_warn("%s: write arg fail\n", key); - return -EIO; - } + if (send_command(cmd) || send_argument(key) || send_byte(len)) + goto err; - if (send_byte(len, APPLESMC_DATA_PORT)) { - pr_warn("%.4s: write len fail\n", key); - return -EIO; - } - - for (i = 0; i < len; i++) { - if (send_byte(buffer[i], APPLESMC_DATA_PORT)) { - pr_warn("%s: write data fail\n", key); - return -EIO; - } - } + for (i = 0; i < len; i++) + if (send_byte(buffer[i])) + goto err; return wait_status(0, SMC_STATUS_BUSY); +err: + pr_warn("write cmd fail: %x %.4s %d\n", cmd, key, len); + return -EIO; } static int read_register_count(unsigned int *count)