public inbox for linux-hwmon@vger.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Brad Campbell <brad@fnarfbargle.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v2] applesmc: Cleanups on top of re-work comms
Date: Thu, 12 Nov 2020 17:17:57 -0800	[thread overview]
Message-ID: <20201113011757.GA208190@roeck-us.net> (raw)
In-Reply-To: <4a99004c-e0e8-1b42-cbbd-ad727a238a64@fnarfbargle.com>

On Fri, Nov 13, 2020 at 09:38:07AM +1100, Brad Campbell wrote:
> A couple of small cleanups on top of the comms changes for applesmc.c :
> 
> send_byte() is always called with APPLESMC_CMD_PORT.
> Consolidate writing length with other setup parameters.
> Consolidate read and write error messages to a single statement each.
> 
> Suggested-by: Henrik Rydberg <rydberg@bitmath.org>
> Signed-off-by: Brad Campbell <brad@fnarfbargle.com>

Changes are ok with me. Can I get some Reviewed-by: / Tested-by: tags ?

Thanks,
Guenter

> ---
> Changelog :
> v1 : Initial cleanup
> v2 : Re-work to suit smc-comms rework v6
> 
> Index: linux-stable/drivers/hwmon/applesmc.c
> ===================================================================
> --- linux-stable.orig/drivers/hwmon/applesmc.c
> +++ linux-stable/drivers/hwmon/applesmc.c
> @@ -182,7 +182,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;
>  
> @@ -199,7 +199,7 @@ static int send_byte(u8 cmd, u16 port)
>  	if (status)
>  		return status;
>  
> -	outb(cmd, port);
> +	outb(cmd, APPLESMC_DATA_PORT);
>  	return 0;
>  }
>  
> @@ -240,7 +240,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;
>  }
> @@ -255,23 +255,13 @@ 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)) {
> -			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);
>  	}
>  
> @@ -287,6 +277,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)
> @@ -298,24 +291,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_byte(len, APPLESMC_DATA_PORT)) {
> -		pr_warn("%.4s: write 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 (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)

      reply	other threads:[~2020-11-13  1:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-12 22:38 [PATCH v2] applesmc: Cleanups on top of re-work comms Brad Campbell
2020-11-13  1:17 ` Guenter Roeck [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201113011757.GA208190@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=brad@fnarfbargle.com \
    --cc=linux-hwmon@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox