linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Andy Shevchenko <andy.shevchenko@gmail.com>,
	Denis Pauk <pauk.denis@gmail.com>
Cc: "Bernhard Seibold" <mail@bernhard-seibold.de>,
	"Pär Ekholm" <pehlm@pekholm.org>,
	to.eivind@gmail.com, "Artem S . Tashkinov" <aros@gmx.com>,
	"Vittorio Roberto Alfieri" <me@rebtoor.com>,
	"Sahan Fernando" <sahan.h.fernando@gmail.com>,
	"Andy Shevchenko" <andriy.shevchenko@intel.com>,
	"Jean Delvare" <jdelvare@suse.com>,
	linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 3/3] hwmon: (nct6775) Support access via Asus WMI.
Date: Thu, 16 Sep 2021 06:21:03 -0700	[thread overview]
Message-ID: <2b0965e4-13b7-0179-fa1f-09d9e444ab96@roeck-us.net> (raw)
In-Reply-To: <CAHp75Vfj6yUrYxbCmYuw=poVjY3GmEBrhF2tJHqkKDVtQ4mywA@mail.gmail.com>

On 9/16/21 1:34 AM, Andy Shevchenko wrote:
> On Wed, Sep 15, 2021 at 11:45 PM Denis Pauk <pauk.denis@gmail.com> wrote:
>>
>> Support accessing the NCT677x via Asus WMI functions.
>>
>> On mainboards that support this way of accessing the chip, the driver will
>> usually not work without this option since in these mainboards, ACPI will
>> mark the I/O port as used.
>>
>> Code uses ACPI firmware interface to commucate with sensors with ASUS
> 
> communicate
> 
>> motherboards:
>> * PRIME B460-PLUS,
>> * ROG CROSSHAIR VIII IMPACT,
>> * ROG STRIX B550-E GAMING,
>> * ROG STRIX B550-F GAMING,
>> * ROG STRIX B550-F GAMING (WI-FI),
>> * ROG STRIX Z490-I GAMING,
>> * TUF GAMING B550M-PLUS,
>> * TUF GAMING B550M-PLUS (WI-FI),
>> * TUF GAMING B550-PLUS,
>> * TUF GAMING X570-PLUS,
>> * TUF GAMING X570-PRO (WI-FI).
> 
> ...
> 
>> +static int asuswmi_evaluate_method(u32 method_id, u8 bank, u8 reg, u8 val, u32 *retval)
>> +{
> 
>> +#if IS_ENABLED(CONFIG_ACPI_WMI)
> 
> The idea behind IS_ENABLED() macro is that it may be used in C
> conditionals, like
> 
> if (IS_ENABLED(...))
> 

It can be and is used either way.

$ git grep "#if IS_ENABLED" | wc
    3126    6529  199841

$ git grep "if (IS_ENABLED" | wc
    1624    6871  120270

>> +       u32 args = bank | (reg << 8) | (val << 16);
>> +       struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
>> +       struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
>> +       acpi_status status;
>> +       union acpi_object *obj;
>> +       u32 tmp = 0;
> 
>> +       obj = output.pointer;
>> +       if (obj && obj->type == ACPI_TYPE_INTEGER)
>> +               tmp = obj->integer.value;
>> +
>> +       if (retval)
>> +               *retval = tmp;
>> +
>> +       kfree(obj);
> 
>> +       if (tmp == ASUSWMI_UNSUPPORTED_METHOD)
> 
> This is uninitialized tmp in case when no obj, or obj is of the wrong type.
> 

In this situation, we know that the ACPI call succeeded. My assumption was
that this code explicitly checks for a specific error code returned from
the ASUS WMI code, which would be returned as integer. This is an additional
error check on top of previous error checks, and it looks perfectly valid to me.

Other WMI code doesn't check for errors other than "if (ACPI_FAILURE(status))".

>> +               return -ENODEV;
>> +       return 0;
>> +#else
>> +       return -EOPNOTSUPP;
>> +#endif
>> +}
> 
> ...
> 
>> +static u16 nct6775_wmi_read_value(struct nct6775_data *data, u16 reg)
>> +{
>> +       int res, word_sized = is_word_sized(data, reg);
>> +       u8 tmp;
>> +
>> +       nct6775_wmi_set_bank(data, reg);
>> +
>> +       nct6775_asuswmi_read(data->bank, reg, &tmp);
> 
>> +       res = (tmp & 0xff);
> 
> Too many parentheses.
> tnp is u8, ' & 0xff' is redundant.
> 
>> +       if (word_sized) {
>> +               nct6775_asuswmi_read(data->bank, (reg & 0xff) + 1, &tmp);
>> +               res = (res << 8) + (tmp & 0xff);
> 
> Ditto.
> 
>> +       }
>> +       return res;
>> +}
>> +
>> +static int nct6775_wmi_write_value(struct nct6775_data *data, u16 reg, u16 value)
>> +{
>> +       int word_sized = is_word_sized(data, reg);
>> +
>> +       nct6775_wmi_set_bank(data, reg);
>> +
>> +       if (word_sized) {
> 
>> +               nct6775_asuswmi_write(data->bank, (reg & 0xff),
> 
> Too many parentheses
> 
>> +                                     (value >> 8) & 0xff);
> 
> ' & 0xff' part is redundant.
> 
>> +               nct6775_asuswmi_write(data->bank, (reg & 0xff) + 1,
>> +                                     value & 0xff);
>> +       } else {
>> +               nct6775_asuswmi_write(data->bank, (reg & 0xff), value);
>> +       }
>> +
>> +       return 0;
>> +}
> 
> ...
> 
>> +               err = match_string(asus_wmi_boards, ARRAY_SIZE(asus_wmi_boards),
>> +                                  board_name);
> 
>> +               if (err != -EINVAL) {
> 
> I believe I commented on this in the way as
> 
> if (err >= 0)
> 
> The rationale behind is that you shouldn't really care what kind of
> error codes the API may return.
> 
>> +                       /* if reading chip id via WMI succeeds, use WMI */
>> +                       if (!nct6775_asuswmi_read(0, NCT6775_PORT_CHIPID, &tmp)) {
>> +                               pr_info("Using Asus WMI to access %#x chip.\n", tmp);
>> +                               access = access_asuswmi;
>> +                       } else {
>> +                               pr_err("Can't read ChipID by Asus WMI.\n");
>> +                       }
>> +               }
> 


  reply	other threads:[~2021-09-16 13:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-15 20:42 [PATCH v6 0/3] hwmon: Support access to the NCT677x via Asus WMI Denis Pauk
2021-09-15 20:42 ` [PATCH v6 1/3] hwmon: (nct6775) Use superio_*() function pointers in sio_data Denis Pauk
2021-09-15 20:42 ` [PATCH v6 2/3] hwmon: (nct6775) Use nct6775_*() function pointers in nct6775_data Denis Pauk
2021-09-15 20:42 ` [PATCH v6 3/3] hwmon: (nct6775) Support access via Asus WMI Denis Pauk
2021-09-16  8:34   ` Andy Shevchenko
2021-09-16 13:21     ` Guenter Roeck [this message]
2021-09-16 13:23     ` Guenter Roeck

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=2b0965e4-13b7-0179-fa1f-09d9e444ab96@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=andriy.shevchenko@intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=aros@gmx.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mail@bernhard-seibold.de \
    --cc=me@rebtoor.com \
    --cc=pauk.denis@gmail.com \
    --cc=pehlm@pekholm.org \
    --cc=sahan.h.fernando@gmail.com \
    --cc=to.eivind@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).