Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1540020 > unrolled thread

[PATCH] firmware: simplify defining and handling FW_OPT_FALLBACK

Started byRafał Miłecki <zajec5@gmail.com>
First post2016-12-11 14:30 +0100
Last post2016-12-12 11:30 +0100
Articles 3 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] firmware: simplify defining and handling FW_OPT_FALLBACK Rafał Miłecki <zajec5@gmail.com> - 2016-12-11 14:30 +0100
    [PATCH V2] firmware: simplify defining and handling FW_OPT_FALLBACK Rafał Miłecki <zajec5@gmail.com> - 2016-12-11 22:30 +0100
      Re: [PATCH V2] firmware: simplify defining and handling FW_OPT_FALLBACK Rafał Miłecki <zajec5@gmail.com> - 2016-12-12 11:30 +0100

#1540020 — [PATCH] firmware: simplify defining and handling FW_OPT_FALLBACK

FromRafał Miłecki <zajec5@gmail.com>
Date2016-12-11 14:30 +0100
Subject[PATCH] firmware: simplify defining and handling FW_OPT_FALLBACK
Message-ID<sNcmt-86u-3@gated-at.bofh.it>
From: Rafał Miłecki <rafal@milecki.pl>

I found handling of FW_OPT_FALLBACK a bit complex. It was defined using
another option and their values were dependent on kernel config.

It was also non-trivial to follow the code. Some callers were using
FW_OPT_FALLBACK which was confusing since the _request_firmware function
was always checking for FW_OPT_USERHELPER (the same bit in a relevan
configuration).

With this patch FW_OPT_USERHELPER gets its own bit and is explicitly
checked in the _request_firmware which hopefully makes code easier to
understand.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 drivers/base/firmware_class.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 22d1760..0524f8b 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -112,13 +112,9 @@ static inline long firmware_loading_timeout(void)
 #else
 #define FW_OPT_USERHELPER	0
 #endif
-#ifdef CONFIG_FW_LOADER_USER_HELPER_FALLBACK
-#define FW_OPT_FALLBACK		FW_OPT_USERHELPER
-#else
-#define FW_OPT_FALLBACK		0
-#endif
 #define FW_OPT_NO_WARN	(1U << 3)
 #define FW_OPT_NOCACHE	(1U << 4)
+#define FW_OPT_FALLBACK	(1U << 5)
 
 struct firmware_cache {
 	/* firmware_buf instance will be added into the below list */
@@ -1175,8 +1171,12 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
 			dev_warn(device,
 				 "Direct firmware load for %s failed with error %d\n",
 				 name, ret);
-		if (opt_flags & FW_OPT_USERHELPER) {
+		if (config_enabled(CONFIG_FW_LOADER_USER_HELPER_FALLBACK) &&
+		    opt_flags & FW_OPT_FALLBACK) {
 			dev_warn(device, "Falling back to user helper\n");
+			opt_flags |= FW_OPT_USERHELPER;
+		}
+		if (opt_flags & FW_OPT_USERHELPER) {
 			ret = fw_load_from_user_helper(fw, name, device,
 						       opt_flags, timeout);
 		}
-- 
2.10.1

[toc] | [next] | [standalone]


#1540065 — [PATCH V2] firmware: simplify defining and handling FW_OPT_FALLBACK

FromRafał Miłecki <zajec5@gmail.com>
Date2016-12-11 22:30 +0100
Subject[PATCH V2] firmware: simplify defining and handling FW_OPT_FALLBACK
Message-ID<sNjR0-49m-3@gated-at.bofh.it>
In reply to#1540020
From: Rafał Miłecki <rafal@milecki.pl>

I found handling of FW_OPT_FALLBACK a bit complex. It was defined using
another option and their values were dependent on kernel config.

It was also non-trivial to follow the code. Some callers were using
FW_OPT_FALLBACK which was confusing since the _request_firmware function
was always checking for FW_OPT_USERHELPER (the same bit in a relevant
configuration).

With this patch FW_OPT_USERHELPER gets its own bit and is explicitly
checked in the _request_firmware which hopefully makes code easier to
understand.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
V2: s/config_enabled/IS_ENABLED/ to compile since c0a0aba8e47 ("kconfig.h: remove config_enabled() macro")
---
 drivers/base/firmware_class.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 22d1760..0e1d5b8 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -112,13 +112,9 @@ static inline long firmware_loading_timeout(void)
 #else
 #define FW_OPT_USERHELPER	0
 #endif
-#ifdef CONFIG_FW_LOADER_USER_HELPER_FALLBACK
-#define FW_OPT_FALLBACK		FW_OPT_USERHELPER
-#else
-#define FW_OPT_FALLBACK		0
-#endif
 #define FW_OPT_NO_WARN	(1U << 3)
 #define FW_OPT_NOCACHE	(1U << 4)
+#define FW_OPT_FALLBACK	(1U << 5)
 
 struct firmware_cache {
 	/* firmware_buf instance will be added into the below list */
@@ -1175,8 +1171,12 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
 			dev_warn(device,
 				 "Direct firmware load for %s failed with error %d\n",
 				 name, ret);
-		if (opt_flags & FW_OPT_USERHELPER) {
+		if (IS_ENABLED(CONFIG_FW_LOADER_USER_HELPER_FALLBACK) &&
+		    opt_flags & FW_OPT_FALLBACK) {
 			dev_warn(device, "Falling back to user helper\n");
+			opt_flags |= FW_OPT_USERHELPER;
+		}
+		if (opt_flags & FW_OPT_USERHELPER) {
 			ret = fw_load_from_user_helper(fw, name, device,
 						       opt_flags, timeout);
 		}
-- 
2.10.1

[toc] | [prev] | [next] | [standalone]


#1540241 — Re: [PATCH V2] firmware: simplify defining and handling FW_OPT_FALLBACK

FromRafał Miłecki <zajec5@gmail.com>
Date2016-12-12 11:30 +0100
SubjectRe: [PATCH V2] firmware: simplify defining and handling FW_OPT_FALLBACK
Message-ID<sNw1P-37y-11@gated-at.bofh.it>
In reply to#1540065
On 11 December 2016 at 23:46, Arend van Spriel
<arend.vanspriel@broadcom.com> wrote:
> On 11-12-16 22:21, Rafał Miłecki wrote:
>> From: Rafał Miłecki <rafal@milecki.pl>
>>
>> I found handling of FW_OPT_FALLBACK a bit complex. It was defined using
>> another option and their values were dependent on kernel config.
>>
>> It was also non-trivial to follow the code. Some callers were using
>> FW_OPT_FALLBACK which was confusing since the _request_firmware function
>> was always checking for FW_OPT_USERHELPER (the same bit in a relevant
>> configuration).
>>
>> With this patch FW_OPT_USERHELPER gets its own bit and is explicitly
>> checked in the _request_firmware which hopefully makes code easier to
>> understand.
>>
>> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
>> ---
>> V2: s/config_enabled/IS_ENABLED/ to compile since c0a0aba8e47 ("kconfig.h: remove config_enabled() macro")
>> ---
>>  drivers/base/firmware_class.c | 12 ++++++------
>>  1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
>> index 22d1760..0e1d5b8 100644
>> --- a/drivers/base/firmware_class.c
>> +++ b/drivers/base/firmware_class.c
>> @@ -112,13 +112,9 @@ static inline long firmware_loading_timeout(void)
>>  #else
>>  #define FW_OPT_USERHELPER    0
>>  #endif
>> -#ifdef CONFIG_FW_LOADER_USER_HELPER_FALLBACK
>> -#define FW_OPT_FALLBACK              FW_OPT_USERHELPER
>> -#else
>> -#define FW_OPT_FALLBACK              0
>> -#endif
>>  #define FW_OPT_NO_WARN       (1U << 3)
>>  #define FW_OPT_NOCACHE       (1U << 4)
>> +#define FW_OPT_FALLBACK      (1U << 5)
>>
>>  struct firmware_cache {
>>       /* firmware_buf instance will be added into the below list */
>> @@ -1175,8 +1171,12 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
>>                       dev_warn(device,
>>                                "Direct firmware load for %s failed with error %d\n",
>>                                name, ret);
>> -             if (opt_flags & FW_OPT_USERHELPER) {
>> +             if (IS_ENABLED(CONFIG_FW_LOADER_USER_HELPER_FALLBACK) &&
>> +                 opt_flags & FW_OPT_FALLBACK) {
>
> When mixing logical and binary expressions I would suggest putting the
> binary expression between brackets.

I checked my patch with checkpatch.pl before sending and it didn't
complain. I just re-read CodingStyle but I didn't find any info on
this.

It this some upstream-documented preference for coding style?

-- 
Rafał

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web