* [PATCH] mfd: macsmc: Fix key count endianness annotation
@ 2026-07-19 13:00 Sven Peter
2026-07-19 15:02 ` Joshua Peisach
0 siblings, 1 reply; 4+ messages in thread
From: Sven Peter @ 2026-07-19 13:00 UTC (permalink / raw)
To: Janne Grunau, Neal Gompa, Lee Jones
Cc: asahi, linux-arm-kernel, linux-kernel, kernel test robot,
Sven Peter
SMC firmware returns the value of the #KEY key in big-endian unlike most
other keys. Reading it through apple_smc_read_u32() into a plain u32
and then converting with be32_to_cpu() makes sparse complain:
drivers/mfd/macsmc.c:462:26: sparse: cast to restricted __be32
Read the raw value into a __be32 using apple_smc_read() instead.
Fixes: e038d985c982 ("mfd: Add Apple Silicon System Management Controller")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202607181046.OANjIoqR-lkp@intel.com/
Signed-off-by: Sven Peter <sven@kernel.org>
---
drivers/mfd/macsmc.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c
index 358feec2d088..514cba7dc897 100644
--- a/drivers/mfd/macsmc.c
+++ b/drivers/mfd/macsmc.c
@@ -410,7 +410,7 @@ static int apple_smc_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct apple_smc *smc;
- u32 count;
+ __be32 count;
int ret;
smc = devm_kzalloc(dev, sizeof(*smc), GFP_KERNEL);
@@ -461,8 +461,10 @@ static int apple_smc_probe(struct platform_device *pdev)
dev_set_drvdata(&pdev->dev, smc);
BLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers);
- ret = apple_smc_read_u32(smc, SMC_KEY(#KEY), &count);
- if (ret)
+ ret = apple_smc_read(smc, SMC_KEY(#KEY), &count, sizeof(count));
+ if (ret >= 0 && ret != sizeof(count))
+ ret = -EINVAL;
+ if (ret < 0)
return dev_err_probe(smc->dev, ret, "Failed to get key count");
smc->key_count = be32_to_cpu(count);
---
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
change-id: 20260719-b4-macsmc-be32-fix-637e8bb1692a
Best regards,
--
Sven Peter <sven@kernel.org>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mfd: macsmc: Fix key count endianness annotation
2026-07-19 13:00 [PATCH] mfd: macsmc: Fix key count endianness annotation Sven Peter
@ 2026-07-19 15:02 ` Joshua Peisach
2026-07-19 15:15 ` Sven Peter
0 siblings, 1 reply; 4+ messages in thread
From: Joshua Peisach @ 2026-07-19 15:02 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Neal Gompa, Lee Jones
Cc: asahi, linux-arm-kernel, linux-kernel, kernel test robot
On Sun Jul 19, 2026 at 9:00 AM EDT, Sven Peter wrote:
> SMC firmware returns the value of the #KEY key in big-endian unlike most
> other keys. Reading it through apple_smc_read_u32() into a plain u32
> and then converting with be32_to_cpu() makes sparse complain:
>
> drivers/mfd/macsmc.c:462:26: sparse: cast to restricted __be32
>
> Read the raw value into a __be32 using apple_smc_read() instead.
>
> Fixes: e038d985c982 ("mfd: Add Apple Silicon System Management Controller")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202607181046.OANjIoqR-lkp@intel.com/
> Signed-off-by: Sven Peter <sven@kernel.org>
> ---
> drivers/mfd/macsmc.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c
> index 358feec2d088..514cba7dc897 100644
> --- a/drivers/mfd/macsmc.c
> +++ b/drivers/mfd/macsmc.c
> @@ -410,7 +410,7 @@ static int apple_smc_probe(struct platform_device *pdev)
> {
> struct device *dev = &pdev->dev;
> struct apple_smc *smc;
> - u32 count;
> + __be32 count;
> int ret;
>
> smc = devm_kzalloc(dev, sizeof(*smc), GFP_KERNEL);
> @@ -461,8 +461,10 @@ static int apple_smc_probe(struct platform_device *pdev)
> dev_set_drvdata(&pdev->dev, smc);
> BLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers);
>
> - ret = apple_smc_read_u32(smc, SMC_KEY(#KEY), &count);
> - if (ret)
> + ret = apple_smc_read(smc, SMC_KEY(#KEY), &count, sizeof(count));
> + if (ret >= 0 && ret != sizeof(count))
> + ret = -EINVAL;
> + if (ret < 0)
> return dev_err_probe(smc->dev, ret, "Failed to get key count");
> smc->key_count = be32_to_cpu(count);
This makes sense, it just feels weird reading because u32 is.. not a
be32 (that gets passed into be32_to_cpu).
I guess it doesn't really matter.
-Josh
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mfd: macsmc: Fix key count endianness annotation
2026-07-19 15:02 ` Joshua Peisach
@ 2026-07-19 15:15 ` Sven Peter
2026-07-19 15:28 ` Joshua Peisach
0 siblings, 1 reply; 4+ messages in thread
From: Sven Peter @ 2026-07-19 15:15 UTC (permalink / raw)
To: Joshua Peisach
Cc: asahi, Janne Grunau, Lee Jones, Neal Gompa, linux-arm-kernel,
linux-kernel, kernel test robot
On 7/19/26 17:02, Joshua Peisach wrote:
> On Sun Jul 19, 2026 at 9:00 AM EDT, Sven Peter wrote:
>> SMC firmware returns the value of the #KEY key in big-endian unlike most
>> other keys. Reading it through apple_smc_read_u32() into a plain u32
>> and then converting with be32_to_cpu() makes sparse complain:
>>
>> drivers/mfd/macsmc.c:462:26: sparse: cast to restricted __be32
>>
>> Read the raw value into a __be32 using apple_smc_read() instead.
>>
>> Fixes: e038d985c982 ("mfd: Add Apple Silicon System Management
>> Controller")
>> Reported-by: kernel test robot <lkp@intel.com>
>> Closes:
>> https://lore.kernel.org/oe-kbuild-all/202607181046.OANjIoqR-lkp@intel.com/
>> Signed-off-by: Sven Peter <sven@kernel.org>
>> ---
>> drivers/mfd/macsmc.c | 8 +++++---
>> 1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c
>> index 358feec2d088..514cba7dc897 100644
>> --- a/drivers/mfd/macsmc.c
>> +++ b/drivers/mfd/macsmc.c
>> @@ -410,7 +410,7 @@ static int apple_smc_probe(struct platform_device
>> *pdev)
>> {
>> struct device *dev = &pdev->dev;
>> struct apple_smc *smc;
>> - u32 count;
>> + __be32 count;
>> int ret;
>>
>> smc = devm_kzalloc(dev, sizeof(*smc), GFP_KERNEL);
>> @@ -461,8 +461,10 @@ static int apple_smc_probe(struct
>> platform_device *pdev)
>> dev_set_drvdata(&pdev->dev, smc);
>> BLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers);
>>
>> - ret = apple_smc_read_u32(smc, SMC_KEY(#KEY), &count);
>> - if (ret)
>> + ret = apple_smc_read(smc, SMC_KEY(#KEY), &count, sizeof(count));
>> + if (ret >= 0 && ret != sizeof(count))
>> + ret = -EINVAL;
>> + if (ret < 0)
>> return dev_err_probe(smc->dev, ret, "Failed to get key count");
>> smc->key_count = be32_to_cpu(count);
>
> This makes sense, it just feels weird reading because u32 is.. not a
> be32 (that gets passed into be32_to_cpu).
count is __be32 now (the SMC firmware returns that value as big-endian
because Apple likes to think different) and we read that using
apple_smc_read now which just reads raw bytes. be32_to_cpu then converts
that to a u32, i.e. the type of smc->key_count. There's no functional
change here. What's weird about that?
Sven
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mfd: macsmc: Fix key count endianness annotation
2026-07-19 15:15 ` Sven Peter
@ 2026-07-19 15:28 ` Joshua Peisach
0 siblings, 0 replies; 4+ messages in thread
From: Joshua Peisach @ 2026-07-19 15:28 UTC (permalink / raw)
To: Sven Peter, Joshua Peisach
Cc: asahi, Janne Grunau, Lee Jones, Neal Gompa, linux-arm-kernel,
linux-kernel, kernel test robot
On Sun Jul 19, 2026 at 11:15 AM EDT, Sven Peter wrote:
>
>
> On 7/19/26 17:02, Joshua Peisach wrote:
>> On Sun Jul 19, 2026 at 9:00 AM EDT, Sven Peter wrote:
>>> SMC firmware returns the value of the #KEY key in big-endian unlike most
>>> other keys. Reading it through apple_smc_read_u32() into a plain u32
>>> and then converting with be32_to_cpu() makes sparse complain:
>>>
>>> drivers/mfd/macsmc.c:462:26: sparse: cast to restricted __be32
>>>
>>> Read the raw value into a __be32 using apple_smc_read() instead.
>>>
>>> Fixes: e038d985c982 ("mfd: Add Apple Silicon System Management
>>> Controller")
>>> Reported-by: kernel test robot <lkp@intel.com>
>>> Closes:
>>> https://lore.kernel.org/oe-kbuild-all/202607181046.OANjIoqR-lkp@intel.com/
>>> Signed-off-by: Sven Peter <sven@kernel.org>
>>> ---
>>> drivers/mfd/macsmc.c | 8 +++++---
>>> 1 file changed, 5 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c
>>> index 358feec2d088..514cba7dc897 100644
>>> --- a/drivers/mfd/macsmc.c
>>> +++ b/drivers/mfd/macsmc.c
>>> @@ -410,7 +410,7 @@ static int apple_smc_probe(struct platform_device
>>> *pdev)
>>> {
>>> struct device *dev = &pdev->dev;
>>> struct apple_smc *smc;
>>> - u32 count;
>>> + __be32 count;
>>> int ret;
>>>
>>> smc = devm_kzalloc(dev, sizeof(*smc), GFP_KERNEL);
>>> @@ -461,8 +461,10 @@ static int apple_smc_probe(struct
>>> platform_device *pdev)
>>> dev_set_drvdata(&pdev->dev, smc);
>>> BLOCKING_INIT_NOTIFIER_HEAD(&smc->event_handlers);
>>>
>>> - ret = apple_smc_read_u32(smc, SMC_KEY(#KEY), &count);
>>> - if (ret)
>>> + ret = apple_smc_read(smc, SMC_KEY(#KEY), &count, sizeof(count));
>>> + if (ret >= 0 && ret != sizeof(count))
>>> + ret = -EINVAL;
>>> + if (ret < 0)
>>> return dev_err_probe(smc->dev, ret, "Failed to get key count");
>>> smc->key_count = be32_to_cpu(count);
>>
>> This makes sense, it just feels weird reading because u32 is.. not a
>> be32 (that gets passed into be32_to_cpu).
>
> count is __be32 now (the SMC firmware returns that value as big-endian
> because Apple likes to think different) and we read that using
> apple_smc_read now which just reads raw bytes. be32_to_cpu then converts
> that to a u32, i.e. the type of smc->key_count. There's no functional
> change here. What's weird about that?
>
>
> Sven
Pfft, brain fart. I thought you were going other way around.
Reviewed-by: Joshua Peisach <jpeisach@ubuntu.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-07-19 15:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-19 13:00 [PATCH] mfd: macsmc: Fix key count endianness annotation Sven Peter
2026-07-19 15:02 ` Joshua Peisach
2026-07-19 15:15 ` Sven Peter
2026-07-19 15:28 ` Joshua Peisach
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox