2022-03-24 13:49:06

by Russ Weight

[permalink] [raw]
Subject: [RESEND PATCH v1 2/8] firmware_loader: Check fw_state_is_done in loading_store

Add the fw_state_is_done() function and exit early from
firmware_loading_store() if the state is already "done". This is being done
in preparation for supporting persistent sysfs nodes to allow userspace to
upload firmware to a device, potentially reusing the sysfs loading and data
files multiple times.

Signed-off-by: Russ Weight <[email protected]>
---
v1:
- No change from RFC patch
---
drivers/base/firmware_loader/fallback.c | 2 +-
drivers/base/firmware_loader/firmware.h | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c
index 4afb0e9312c0..d82e055a4297 100644
--- a/drivers/base/firmware_loader/fallback.c
+++ b/drivers/base/firmware_loader/fallback.c
@@ -250,7 +250,7 @@ static ssize_t firmware_loading_store(struct device *dev,

mutex_lock(&fw_lock);
fw_priv = fw_sysfs->fw_priv;
- if (fw_state_is_aborted(fw_priv))
+ if (fw_state_is_aborted(fw_priv) || fw_state_is_done(fw_priv))
goto out;

switch (loading) {
diff --git a/drivers/base/firmware_loader/firmware.h b/drivers/base/firmware_loader/firmware.h
index 2889f446ad41..58768d16f8df 100644
--- a/drivers/base/firmware_loader/firmware.h
+++ b/drivers/base/firmware_loader/firmware.h
@@ -149,6 +149,11 @@ static inline void fw_state_done(struct fw_priv *fw_priv)
__fw_state_set(fw_priv, FW_STATUS_DONE);
}

+static inline bool fw_state_is_done(struct fw_priv *fw_priv)
+{
+ return __fw_state_check(fw_priv, FW_STATUS_DONE);
+}
+
int assign_fw(struct firmware *fw, struct device *device);

#ifdef CONFIG_FW_LOADER
--
2.25.1


2022-04-05 03:16:56

by Tom Rix

[permalink] [raw]
Subject: Re: [RESEND PATCH v1 2/8] firmware_loader: Check fw_state_is_done in loading_store


On 3/23/22 4:33 PM, Russ Weight wrote:
> Add the fw_state_is_done() function and exit early from
> firmware_loading_store() if the state is already "done". This is being done
> in preparation for supporting persistent sysfs nodes to allow userspace to
> upload firmware to a device, potentially reusing the sysfs loading and data
> files multiple times.
>
> Signed-off-by: Russ Weight <[email protected]>
> ---
> v1:
> - No change from RFC patch
> ---
> drivers/base/firmware_loader/fallback.c | 2 +-
> drivers/base/firmware_loader/firmware.h | 5 +++++
> 2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c
> index 4afb0e9312c0..d82e055a4297 100644
> --- a/drivers/base/firmware_loader/fallback.c
> +++ b/drivers/base/firmware_loader/fallback.c
> @@ -250,7 +250,7 @@ static ssize_t firmware_loading_store(struct device *dev,
>
> mutex_lock(&fw_lock);
> fw_priv = fw_sysfs->fw_priv;
> - if (fw_state_is_aborted(fw_priv))
> + if (fw_state_is_aborted(fw_priv) || fw_state_is_done(fw_priv))
> goto out;
>
> switch (loading) {
> diff --git a/drivers/base/firmware_loader/firmware.h b/drivers/base/firmware_loader/firmware.h
> index 2889f446ad41..58768d16f8df 100644
> --- a/drivers/base/firmware_loader/firmware.h
> +++ b/drivers/base/firmware_loader/firmware.h
> @@ -149,6 +149,11 @@ static inline void fw_state_done(struct fw_priv *fw_priv)
> __fw_state_set(fw_priv, FW_STATUS_DONE);
> }
>
> +static inline bool fw_state_is_done(struct fw_priv *fw_priv)
> +{
> + return __fw_state_check(fw_priv, FW_STATUS_DONE);

This looks like the fw_sysfs_done() in fallback.c

IMO this one and similar wrappers should move to firmware.h and use the
*_is_* naming.

Tom

> +}
> +
> int assign_fw(struct firmware *fw, struct device *device);
>
> #ifdef CONFIG_FW_LOADER

2022-04-16 01:52:14

by Russ Weight

[permalink] [raw]
Subject: Re: [RESEND PATCH v1 2/8] firmware_loader: Check fw_state_is_done in loading_store



On 4/2/22 07:47, Tom Rix wrote:
>
> On 3/23/22 4:33 PM, Russ Weight wrote:
>> Add the fw_state_is_done() function and exit early from
>> firmware_loading_store() if the state is already "done". This is being done
>> in preparation for supporting persistent sysfs nodes to allow userspace to
>> upload firmware to a device, potentially reusing the sysfs loading and data
>> files multiple times.
>>
>> Signed-off-by: Russ Weight <[email protected]>
>> ---
>> v1:
>>    - No change from RFC patch
>> ---
>>   drivers/base/firmware_loader/fallback.c | 2 +-
>>   drivers/base/firmware_loader/firmware.h | 5 +++++
>>   2 files changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/base/firmware_loader/fallback.c b/drivers/base/firmware_loader/fallback.c
>> index 4afb0e9312c0..d82e055a4297 100644
>> --- a/drivers/base/firmware_loader/fallback.c
>> +++ b/drivers/base/firmware_loader/fallback.c
>> @@ -250,7 +250,7 @@ static ssize_t firmware_loading_store(struct device *dev,
>>         mutex_lock(&fw_lock);
>>       fw_priv = fw_sysfs->fw_priv;
>> -    if (fw_state_is_aborted(fw_priv))
>> +    if (fw_state_is_aborted(fw_priv) || fw_state_is_done(fw_priv))
>>           goto out;
>>         switch (loading) {
>> diff --git a/drivers/base/firmware_loader/firmware.h b/drivers/base/firmware_loader/firmware.h
>> index 2889f446ad41..58768d16f8df 100644
>> --- a/drivers/base/firmware_loader/firmware.h
>> +++ b/drivers/base/firmware_loader/firmware.h
>> @@ -149,6 +149,11 @@ static inline void fw_state_done(struct fw_priv *fw_priv)
>>       __fw_state_set(fw_priv, FW_STATUS_DONE);
>>   }
>>   +static inline bool fw_state_is_done(struct fw_priv *fw_priv)
>> +{
>> +    return __fw_state_check(fw_priv, FW_STATUS_DONE);
>
> This looks like the fw_sysfs_done() in fallback.c
>
> IMO this one and similar wrappers should move to firmware.h and use the *_is_* naming.

Thanks for catching that Tom. Yes, the new fw_state_is_done() function is exactly
the same as fw_sysfs_done(). I'll follow your suggestion and move fw_sysfs_done()
and fw_sysfs_loading() to firmware.h as fw_state_is_done() and fw_state_is_loading().

- Russ
>
> Tom
>
>> +}
>> +
>>   int assign_fw(struct firmware *fw, struct device *device);
>>     #ifdef CONFIG_FW_LOADER
>