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


Groups > linux.kernel > #1312595 > unrolled thread

[PATCH v3] dmi: Make dmi_walk and dmi_walk_early return real error codes

Started byAndy Lutomirski <luto@kernel.org>
First post2016-01-20 01:00 +0100
Last post2016-01-22 10:20 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v3] dmi: Make dmi_walk and dmi_walk_early return real error codes Andy Lutomirski <luto@kernel.org> - 2016-01-20 01:00 +0100
    Re: [PATCH v3] dmi: Make dmi_walk and dmi_walk_early return real  error codes Jean Delvare <jdelvare@suse.de> - 2016-01-22 10:20 +0100

#1312595 — [PATCH v3] dmi: Make dmi_walk and dmi_walk_early return real error codes

FromAndy Lutomirski <luto@kernel.org>
Date2016-01-20 01:00 +0100
Subject[PATCH v3] dmi: Make dmi_walk and dmi_walk_early return real error codes
Message-ID<qSOlQ-6sp-21@gated-at.bofh.it>
Currently they return -1 on error, which will confuse callers if
they try to interpret it as a normal negative error code.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---

Changes from v3:
 - Split out from the series it was in.
 - Use -ENXIO for "there's no DMI".
 - Also fix docs and !DMI case.

Changes from v2:
 - Total rewrite.

drivers/firmware/dmi_scan.c | 9 +++++----
 include/linux/dmi.h         | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index 0e08e665f715..0418fed261bb 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -144,7 +144,7 @@ static int __init dmi_walk_early(void (*decode)(const struct dmi_header *,
 
 	buf = dmi_early_remap(dmi_base, orig_dmi_len);
 	if (buf == NULL)
-		return -1;
+		return -ENOMEM;
 
 	dmi_decode_table(buf, decode, NULL);
 
@@ -970,7 +970,8 @@ EXPORT_SYMBOL(dmi_get_date);
  *	@decode: Callback function
  *	@private_data: Private data to be passed to the callback function
  *
- *	Returns -1 when the DMI table can't be reached, 0 on success.
+ *	Returns 0 on success, -ENXIO if DMI is not selected or not present,
+ *	or a different negative error code if DMI walking fails.
  */
 int dmi_walk(void (*decode)(const struct dmi_header *, void *),
 	     void *private_data)
@@ -978,11 +979,11 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
 	u8 *buf;
 
 	if (!dmi_available)
-		return -1;
+		return -ENOENT;
 
 	buf = dmi_remap(dmi_base, dmi_len);
 	if (buf == NULL)
-		return -1;
+		return -ENOMEM;
 
 	dmi_decode_table(buf, decode, private_data);
 
diff --git a/include/linux/dmi.h b/include/linux/dmi.h
index 5055ac34142d..770d548e9a9d 100644
--- a/include/linux/dmi.h
+++ b/include/linux/dmi.h
@@ -135,7 +135,7 @@ static inline int dmi_name_in_vendors(const char *s) { return 0; }
 static inline int dmi_name_in_serial(const char *s) { return 0; }
 #define dmi_available 0
 static inline int dmi_walk(void (*decode)(const struct dmi_header *, void *),
-	void *private_data) { return -1; }
+	void *private_data) { return -ENXIO; }
 static inline bool dmi_match(enum dmi_field f, const char *str)
 	{ return false; }
 static inline void dmi_memdev_name(u16 handle, const char **bank,
-- 
2.5.0

[toc] | [next] | [standalone]


#1314840 — Re: [PATCH v3] dmi: Make dmi_walk and dmi_walk_early return real error codes

FromJean Delvare <jdelvare@suse.de>
Date2016-01-22 10:20 +0100
SubjectRe: [PATCH v3] dmi: Make dmi_walk and dmi_walk_early return real error codes
Message-ID<qTG2S-20Q-3@gated-at.bofh.it>
In reply to#1312595
Hi Andy,

Sorry for the delay.

On Tue, 19 Jan 2016 15:54:46 -0800, Andy Lutomirski wrote:
> Currently they return -1 on error, which will confuse callers if
> they try to interpret it as a normal negative error code.
> 
> Signed-off-by: Andy Lutomirski <luto@kernel.org>
> ---
> 
> Changes from v3:

You mean from v2...

>  - Split out from the series it was in.
>  - Use -ENXIO for "there's no DMI".
>  - Also fix docs and !DMI case.
> 
> Changes from v2:

... and from v1.

>  - Total rewrite.
> 
> drivers/firmware/dmi_scan.c | 9 +++++----
>  include/linux/dmi.h         | 2 +-
>  2 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
> index 0e08e665f715..0418fed261bb 100644
> --- a/drivers/firmware/dmi_scan.c
> +++ b/drivers/firmware/dmi_scan.c
> @@ -144,7 +144,7 @@ static int __init dmi_walk_early(void (*decode)(const struct dmi_header *,
>  
>  	buf = dmi_early_remap(dmi_base, orig_dmi_len);
>  	if (buf == NULL)
> -		return -1;
> +		return -ENOMEM;
>  
>  	dmi_decode_table(buf, decode, NULL);
>  
> @@ -970,7 +970,8 @@ EXPORT_SYMBOL(dmi_get_date);
>   *	@decode: Callback function
>   *	@private_data: Private data to be passed to the callback function
>   *
> - *	Returns -1 when the DMI table can't be reached, 0 on success.
> + *	Returns 0 on success, -ENXIO if DMI is not selected or not present,
> + *	or a different negative error code if DMI walking fails.

Returning an error from DMI walking isn't yet implemented so this is
confusing. If it ever is, most likely it will be implemented as a
separate function. Or were you only referring to the -ENOMEM case below?

>   */
>  int dmi_walk(void (*decode)(const struct dmi_header *, void *),
>  	     void *private_data)
> @@ -978,11 +979,11 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
>  	u8 *buf;
>  
>  	if (!dmi_available)
> -		return -1;
> +		return -ENOENT;

Should be -ENXIO as documented above? Not that I really understand how
"No such device or address" is going to be a helpful error message for
the user. What's wrong with -ENOTSUP I suggested earlier?

>  
>  	buf = dmi_remap(dmi_base, dmi_len);
>  	if (buf == NULL)
> -		return -1;
> +		return -ENOMEM;
>  
>  	dmi_decode_table(buf, decode, private_data);
>  
> diff --git a/include/linux/dmi.h b/include/linux/dmi.h
> index 5055ac34142d..770d548e9a9d 100644
> --- a/include/linux/dmi.h
> +++ b/include/linux/dmi.h
> @@ -135,7 +135,7 @@ static inline int dmi_name_in_vendors(const char *s) { return 0; }
>  static inline int dmi_name_in_serial(const char *s) { return 0; }
>  #define dmi_available 0
>  static inline int dmi_walk(void (*decode)(const struct dmi_header *, void *),
> -	void *private_data) { return -1; }
> +	void *private_data) { return -ENXIO; }
>  static inline bool dmi_match(enum dmi_field f, const char *str)
>  	{ return false; }
>  static inline void dmi_memdev_name(u16 handle, const char **bank,


-- 
Jean Delvare
SUSE L3 Support

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web