All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] efi/apple-properties: Reinstate support for boolean properties
@ 2020-12-31  5:10 Lukas Wunner
  2020-12-31  9:27 ` Ard Biesheuvel
  2021-01-27 19:31 ` [tip: efi/urgent] " tip-bot2 for Lukas Wunner
  0 siblings, 2 replies; 3+ messages in thread
From: Lukas Wunner @ 2020-12-31  5:10 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: Dmitry Torokhov, Andy Shevchenko, linux-efi

Since commit 4466bf82821b ("efi/apple-properties: use
PROPERTY_ENTRY_U8_ARRAY_LEN"), my MacBook Pro issues a -ENODATA error
when trying to assign EFI properties to the discrete GPU:

pci 0000:01:00.0: assigning 56 device properties
pci 0000:01:00.0: error -61 assigning properties

That's because some of the properties have no value.  They're booleans
whose presence can be checked by drivers, e.g. "use-backlight-blanking".

Commit 6e98503dba64 ("efi/apple-properties: Remove redundant attribute
initialization from unmarshal_key_value_pairs()") employed a trick to
store such booleans as u8 arrays (which is the data type used for all
other EFI properties on Macs):  It cleared the property_entry's
"is_array" flag, thereby denoting that the value is stored inline in the
property_entry.

Commit 4466bf82821b erroneously removed that trick.  It was probably a
little fragile to begin with.

Reinstate support for boolean properties by explicitly invoking the
PROPERTY_ENTRY_BOOL() initializer for properties with zero-length value.

Fixes: 4466bf82821b ("efi/apple-properties: use PROPERTY_ENTRY_U8_ARRAY_LEN")
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: stable@vger.kernel.org # v5.5+
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
v1 -> v2: Check for entry_len instead of !entry_len. (Andy)

 drivers/firmware/efi/apple-properties.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/firmware/efi/apple-properties.c b/drivers/firmware/efi/apple-properties.c
index 34f53d898acb..e1926483ae2f 100644
--- a/drivers/firmware/efi/apple-properties.c
+++ b/drivers/firmware/efi/apple-properties.c
@@ -3,8 +3,9 @@
  * apple-properties.c - EFI device properties on Macs
  * Copyright (C) 2016 Lukas Wunner <lukas@wunner.de>
  *
- * Note, all properties are considered as u8 arrays.
- * To get a value of any of them the caller must use device_property_read_u8_array().
+ * Properties are stored either as:
+ * u8 arrays which can be retrieved with device_property_read_u8_array() or
+ * booleans which can be queried with device_property_present().
  */
 
 #define pr_fmt(fmt) "apple-properties: " fmt
@@ -88,8 +89,12 @@ static void __init unmarshal_key_value_pairs(struct dev_header *dev_header,
 
 		entry_data = ptr + key_len + sizeof(val_len);
 		entry_len = val_len - sizeof(val_len);
-		entry[i] = PROPERTY_ENTRY_U8_ARRAY_LEN(key, entry_data,
-						       entry_len);
+		if (entry_len)
+			entry[i] = PROPERTY_ENTRY_U8_ARRAY_LEN(key, entry_data,
+							       entry_len);
+		else
+			entry[i] = PROPERTY_ENTRY_BOOL(key);
+
 		if (dump_properties) {
 			dev_info(dev, "property: %s\n", key);
 			print_hex_dump(KERN_INFO, pr_fmt(), DUMP_PREFIX_OFFSET,
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] efi/apple-properties: Reinstate support for boolean properties
  2020-12-31  5:10 [PATCH v2] efi/apple-properties: Reinstate support for boolean properties Lukas Wunner
@ 2020-12-31  9:27 ` Ard Biesheuvel
  2021-01-27 19:31 ` [tip: efi/urgent] " tip-bot2 for Lukas Wunner
  1 sibling, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2020-12-31  9:27 UTC (permalink / raw)
  To: Lukas Wunner; +Cc: Dmitry Torokhov, Andy Shevchenko, linux-efi

On Thu, 31 Dec 2020 at 06:19, Lukas Wunner <lukas@wunner.de> wrote:
>
> Since commit 4466bf82821b ("efi/apple-properties: use
> PROPERTY_ENTRY_U8_ARRAY_LEN"), my MacBook Pro issues a -ENODATA error
> when trying to assign EFI properties to the discrete GPU:
>
> pci 0000:01:00.0: assigning 56 device properties
> pci 0000:01:00.0: error -61 assigning properties
>
> That's because some of the properties have no value.  They're booleans
> whose presence can be checked by drivers, e.g. "use-backlight-blanking".
>
> Commit 6e98503dba64 ("efi/apple-properties: Remove redundant attribute
> initialization from unmarshal_key_value_pairs()") employed a trick to
> store such booleans as u8 arrays (which is the data type used for all
> other EFI properties on Macs):  It cleared the property_entry's
> "is_array" flag, thereby denoting that the value is stored inline in the
> property_entry.
>
> Commit 4466bf82821b erroneously removed that trick.  It was probably a
> little fragile to begin with.
>
> Reinstate support for boolean properties by explicitly invoking the
> PROPERTY_ENTRY_BOOL() initializer for properties with zero-length value.
>
> Fixes: 4466bf82821b ("efi/apple-properties: use PROPERTY_ENTRY_U8_ARRAY_LEN")
> Signed-off-by: Lukas Wunner <lukas@wunner.de>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: stable@vger.kernel.org # v5.5+
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
> v1 -> v2: Check for entry_len instead of !entry_len. (Andy)

Thanks Lukas. I will queue this as a fix.


>
>  drivers/firmware/efi/apple-properties.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/firmware/efi/apple-properties.c b/drivers/firmware/efi/apple-properties.c
> index 34f53d898acb..e1926483ae2f 100644
> --- a/drivers/firmware/efi/apple-properties.c
> +++ b/drivers/firmware/efi/apple-properties.c
> @@ -3,8 +3,9 @@
>   * apple-properties.c - EFI device properties on Macs
>   * Copyright (C) 2016 Lukas Wunner <lukas@wunner.de>
>   *
> - * Note, all properties are considered as u8 arrays.
> - * To get a value of any of them the caller must use device_property_read_u8_array().
> + * Properties are stored either as:
> + * u8 arrays which can be retrieved with device_property_read_u8_array() or
> + * booleans which can be queried with device_property_present().
>   */
>
>  #define pr_fmt(fmt) "apple-properties: " fmt
> @@ -88,8 +89,12 @@ static void __init unmarshal_key_value_pairs(struct dev_header *dev_header,
>
>                 entry_data = ptr + key_len + sizeof(val_len);
>                 entry_len = val_len - sizeof(val_len);
> -               entry[i] = PROPERTY_ENTRY_U8_ARRAY_LEN(key, entry_data,
> -                                                      entry_len);
> +               if (entry_len)
> +                       entry[i] = PROPERTY_ENTRY_U8_ARRAY_LEN(key, entry_data,
> +                                                              entry_len);
> +               else
> +                       entry[i] = PROPERTY_ENTRY_BOOL(key);
> +
>                 if (dump_properties) {
>                         dev_info(dev, "property: %s\n", key);
>                         print_hex_dump(KERN_INFO, pr_fmt(), DUMP_PREFIX_OFFSET,
> --
> 2.29.2
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip: efi/urgent] efi/apple-properties: Reinstate support for boolean properties
  2020-12-31  5:10 [PATCH v2] efi/apple-properties: Reinstate support for boolean properties Lukas Wunner
  2020-12-31  9:27 ` Ard Biesheuvel
@ 2021-01-27 19:31 ` tip-bot2 for Lukas Wunner
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot2 for Lukas Wunner @ 2021-01-27 19:31 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: stable, Andy Shevchenko, Lukas Wunner, Ard Biesheuvel, x86, linux-kernel

The following commit has been merged into the efi/urgent branch of tip:

Commit-ID:     355845b738e76445c8522802552146d96cb4afa7
Gitweb:        https://git.kernel.org/tip/355845b738e76445c8522802552146d96cb4afa7
Author:        Lukas Wunner <lukas@wunner.de>
AuthorDate:    Thu, 31 Dec 2020 06:10:32 +01:00
Committer:     Ard Biesheuvel <ardb@kernel.org>
CommitterDate: Thu, 31 Dec 2020 10:28:53 +01:00

efi/apple-properties: Reinstate support for boolean properties

Since commit 4466bf82821b ("efi/apple-properties: use
PROPERTY_ENTRY_U8_ARRAY_LEN"), my MacBook Pro issues a -ENODATA error
when trying to assign EFI properties to the discrete GPU:

pci 0000:01:00.0: assigning 56 device properties
pci 0000:01:00.0: error -61 assigning properties

That's because some of the properties have no value.  They're booleans
whose presence can be checked by drivers, e.g. "use-backlight-blanking".

Commit 6e98503dba64 ("efi/apple-properties: Remove redundant attribute
initialization from unmarshal_key_value_pairs()") employed a trick to
store such booleans as u8 arrays (which is the data type used for all
other EFI properties on Macs):  It cleared the property_entry's
"is_array" flag, thereby denoting that the value is stored inline in the
property_entry.

Commit 4466bf82821b erroneously removed that trick.  It was probably a
little fragile to begin with.

Reinstate support for boolean properties by explicitly invoking the
PROPERTY_ENTRY_BOOL() initializer for properties with zero-length value.

Fixes: 4466bf82821b ("efi/apple-properties: use PROPERTY_ENTRY_U8_ARRAY_LEN")
Cc: <stable@vger.kernel.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Link: https://lore.kernel.org/r/be958bda75331a011d53c696d1deec8dccd06fd2.1609388549.git.lukas@wunner.de
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/firmware/efi/apple-properties.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/firmware/efi/apple-properties.c b/drivers/firmware/efi/apple-properties.c
index 34f53d8..e192648 100644
--- a/drivers/firmware/efi/apple-properties.c
+++ b/drivers/firmware/efi/apple-properties.c
@@ -3,8 +3,9 @@
  * apple-properties.c - EFI device properties on Macs
  * Copyright (C) 2016 Lukas Wunner <lukas@wunner.de>
  *
- * Note, all properties are considered as u8 arrays.
- * To get a value of any of them the caller must use device_property_read_u8_array().
+ * Properties are stored either as:
+ * u8 arrays which can be retrieved with device_property_read_u8_array() or
+ * booleans which can be queried with device_property_present().
  */
 
 #define pr_fmt(fmt) "apple-properties: " fmt
@@ -88,8 +89,12 @@ static void __init unmarshal_key_value_pairs(struct dev_header *dev_header,
 
 		entry_data = ptr + key_len + sizeof(val_len);
 		entry_len = val_len - sizeof(val_len);
-		entry[i] = PROPERTY_ENTRY_U8_ARRAY_LEN(key, entry_data,
-						       entry_len);
+		if (entry_len)
+			entry[i] = PROPERTY_ENTRY_U8_ARRAY_LEN(key, entry_data,
+							       entry_len);
+		else
+			entry[i] = PROPERTY_ENTRY_BOOL(key);
+
 		if (dump_properties) {
 			dev_info(dev, "property: %s\n", key);
 			print_hex_dump(KERN_INFO, pr_fmt(), DUMP_PREFIX_OFFSET,

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-27 19:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-31  5:10 [PATCH v2] efi/apple-properties: Reinstate support for boolean properties Lukas Wunner
2020-12-31  9:27 ` Ard Biesheuvel
2021-01-27 19:31 ` [tip: efi/urgent] " tip-bot2 for Lukas Wunner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.