From: Hans de Goede <hdegoede@redhat.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Nikita Kravets" <teackot@gmail.com>
Cc: platform-driver-x86@vger.kernel.org,
Aakash Singh <mail@singhaakash.dev>,
Jose Angel Pastrana <japp0005@red.ujaen.es>
Subject: Re: [PATCH 4/5] platform/x86: msi-ec: Add EC bit operation functions
Date: Thu, 12 Oct 2023 14:41:16 +0200 [thread overview]
Message-ID: <894d40dc-4a7b-4cdd-759f-e96112e6a395@redhat.com> (raw)
In-Reply-To: <9ea4b836-38d8-8abd-4222-3acb22ee287@linux.intel.com>
Hi,
On 10/11/23 14:59, Ilpo Järvinen wrote:
> On Tue, 10 Oct 2023, Nikita Kravets wrote:
>
>> The EC of MSI laptops supports several features represented by a single
>> bit. Add ec_set_bit and ec_check_bit functions to operate on these bits.
>>
>> Cc: Aakash Singh <mail@singhaakash.dev>
>> Cc: Jose Angel Pastrana <japp0005@red.ujaen.es>
>> Signed-off-by: Nikita Kravets <teackot@gmail.com>
>> ---
>> drivers/platform/x86/msi-ec.c | 28 ++++++++++++++++++++++++++++
>> 1 file changed, 28 insertions(+)
>>
>> diff --git a/drivers/platform/x86/msi-ec.c b/drivers/platform/x86/msi-ec.c
>> index 09472b21e093..ae73dcf01d09 100644
>> --- a/drivers/platform/x86/msi-ec.c
>> +++ b/drivers/platform/x86/msi-ec.c
>> @@ -699,6 +699,34 @@ static int ec_read_seq(u8 addr, u8 *buf, u8 len)
>> return 0;
>> }
>>
>> +static int ec_set_bit(u8 addr, u8 bit, bool value)
>> +{
>> + int result;
>> + u8 stored;
>> +
>> + result = ec_read(addr, &stored);
>> + if (result < 0)
>> + return result;
>> +
>> + stored ^= (-(u8) value ^ stored) & (1 << bit);
>
> So first you case bool to u8 and then take negation of that unsigned
> number? ...My head is already hurting even without all the other logic.
>
> This has to be rewritten to something that mere mortals can understand
> which doesn't explore all those odd corners of C spec. :-)
>
> I didn't try to parse that logic through but I assuming it's the usual
> construct perhaps this could be simplified with (please be sure to check
> this throughoutly as I didn't try to understand what the original really
> does):
>
> bit = 1 << bit;
> stored &= ~bit;
> stored |= value ? bit : 0;
Right instead of using a bit variable I would suggest
using the BIT(x) macro here:
stored &= ~BIT(bit);
stored |= value ? BIT(bit) : 0;
Also since you are exposing multiple userspace
entry points into the kernel this function may
race with itself, so I think you need to add
a mutex and lock this while doing the
read-modify-write to avoid 2 read-modify-write
cycles from racing with each other.
Regards,
Hans
>
>> +
>> + return ec_write(addr, stored);
>> +}
>> +
>> +static int ec_check_bit(u8 addr, u8 bit, bool *output)
>> +{
>> + int result;
>> + u8 stored;
>> +
>> + result = ec_read(addr, &stored);
>> + if (result < 0)
>> + return result;
>> +
>> + *output = (stored >> bit) & 1;
>> +
>> + return 0;
>> +}
>> +
>> static int ec_get_firmware_version(u8 buf[MSI_EC_FW_VERSION_LENGTH + 1])
>> {
>> int result;
>>
>
next prev parent reply other threads:[~2023-10-12 12:42 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-10 17:20 [PATCH 0/5] platform/x86: msi-ec: Add the first platform device attributes Nikita Kravets
2023-10-10 17:20 ` [PATCH 1/5] platform/x86: msi-ec: Register a platform driver Nikita Kravets
2023-10-11 13:00 ` Ilpo Järvinen
2023-10-12 12:30 ` Hans de Goede
2023-10-10 17:20 ` [PATCH 2/5] platform/x86: msi-ec: Add fw version and release date attributes Nikita Kravets
2023-10-11 12:41 ` Ilpo Järvinen
2023-10-12 12:34 ` Hans de Goede
2023-10-12 12:56 ` Ilpo Järvinen
2023-10-18 14:34 ` Hans de Goede
2025-02-20 12:25 ` N K
2023-10-10 17:20 ` [PATCH 3/5] platform/x86: msi-ec: Filter out unsupported attributes Nikita Kravets
2023-10-11 12:46 ` Ilpo Järvinen
2023-10-10 17:20 ` [PATCH 4/5] platform/x86: msi-ec: Add EC bit operation functions Nikita Kravets
2023-10-11 12:59 ` Ilpo Järvinen
2023-10-12 12:41 ` Hans de Goede [this message]
2023-10-10 17:20 ` [PATCH 5/5] platform/x86: msi-ec: Add a cooler boost attribute Nikita Kravets
2023-10-11 12:49 ` Ilpo Järvinen
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=894d40dc-4a7b-4cdd-759f-e96112e6a395@redhat.com \
--to=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=japp0005@red.ujaen.es \
--cc=mail@singhaakash.dev \
--cc=platform-driver-x86@vger.kernel.org \
--cc=teackot@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