Skip to contentSkip to conversation

staging: greybus: Clear up precedence for gcam logging macros

PATCH In review Jackson Chui 4 participants 8 messages Apr 4, 2024 – Apr 8, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: greybus: Clear up precedence for gcam logging macros

Reported by checkpatch:

CHECK: Macro argument 'gcam' may be better as '(gcam)' to avoid precedence issues

Disambiguates '&' (address-of) operator and '->' operator precedence, accounting for how '(gcam)->bundle->dev' is a 'struct device' and not a 'struct device*', which is required by the dev_{dbg,info,err} driver model diagnostic macros. Issue found by checkpatch.

---
 drivers/staging/greybus/camera.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/greybus/camera.c +3 -3
index a8173aa3a995..d82a2d2abdca 100644
@@ -180,9 +180,9 @@ static const struct gb_camera_fmt_info *gb_camera_get_format_info(u16 gb_fmt)
 
 #define GB_CAMERA_MAX_SETTINGS_SIZE	8192
 
-#define gcam_dbg(gcam, format...)	dev_dbg(&gcam->bundle->dev, format)
-#define gcam_info(gcam, format...)	dev_info(&gcam->bundle->dev, format)
-#define gcam_err(gcam, format...)	dev_err(&gcam->bundle->dev, format)
+#define gcam_dbg(gcam, format...)	dev_dbg(&((gcam)->bundle->dev), format)
+#define gcam_info(gcam, format...)	dev_info(&((gcam)->bundle->dev), format)
+#define gcam_err(gcam, format...)	dev_err(&((gcam)->bundle->dev), format)
 
 static int gb_camera_operation_sync_flags(struct gb_connection *connection,
 					  int type, unsigned int flags,
Signature · 1 line
2.34.1
#1 lore raw
Quoted 4 lines · Jackson Chui

Reported by checkpatch:

CHECK: Macro argument 'gcam' may be better as '(gcam)' to avoid precedence issues

I agree with your argument about the way the macro should be defined. But perhaps these gcam_*() functions could just be eliminated?

I see 15 calls to gcam_err(), 1 call to gcam_dbg(), and none to gcam_info(). It would be a different patch, but maybe you could do that instead?

-Alex

Quoted 28 lines

Disambiguates '&' (address-of) operator and '->' operator precedence, accounting for how '(gcam)->bundle->dev' is a 'struct device' and not a 'struct device*', which is required by the dev_{dbg,info,err} driver model diagnostic macros. Issue found by checkpatch.

---
  drivers/staging/greybus/camera.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/greybus/camera.c +3 -3
index a8173aa3a995..d82a2d2abdca 100644
@@ -180,9 +180,9 @@ static const struct gb_camera_fmt_info *gb_camera_get_format_info(u16 gb_fmt)
 
  #define GB_CAMERA_MAX_SETTINGS_SIZE	8192
 
-#define gcam_dbg(gcam, format...)	dev_dbg(&gcam->bundle->dev, format)
-#define gcam_info(gcam, format...)	dev_info(&gcam->bundle->dev, format)
-#define gcam_err(gcam, format...)	dev_err(&gcam->bundle->dev, format)
+#define gcam_dbg(gcam, format...)	dev_dbg(&((gcam)->bundle->dev), format)
+#define gcam_info(gcam, format...)	dev_info(&((gcam)->bundle->dev), format)
+#define gcam_err(gcam, format...)	dev_err(&((gcam)->bundle->dev), format)
 
  static int gb_camera_operation_sync_flags(struct gb_connection *connection,
  					  int type, unsigned int flags,
#2 lore raw
Quoted 28 lines · Alex Elder
Quoted 4 lines · Jackson Chui

Reported by checkpatch:

CHECK: Macro argument 'gcam' may be better as '(gcam)' to avoid precedence issues

I agree with your argument about the way the macro should be defined. But perhaps these gcam_*() functions could just be eliminated?

I see 15 calls to gcam_err(), 1 call to gcam_dbg(), and none to gcam_info(). It would be a different patch, but maybe you could do that instead?

-Alex

Quoted 11 lines

Disambiguates '&' (address-of) operator and '->' operator precedence, accounting for how '(gcam)->bundle->dev' is a 'struct device' and not a 'struct device*', which is required by the dev_{dbg,info,err} driver model diagnostic macros. Issue found by checkpatch.

---
  drivers/staging/greybus/camera.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 15 lines
Quoted 5 lines
drivers/staging/greybus/camera.c +0 -0
index a8173aa3a995..d82a2d2abdca 100644

drivers/staging/greybus/camera.c static const struct gb_camera_fmt_info *gb_camera_get_format_info(u16 gb_fmt) · line 185

Quoted 9 lines
drivers/staging/greybus/camera.c +3 -3
@@ -180,9 +180,9 @@ static const struct gb_camera_fmt_info *gb_camera_get_format_info(u16 gb_fmt)
  #define GB_CAMERA_MAX_SETTINGS_SIZE	8192
-#define gcam_dbg(gcam, format...)	dev_dbg(&gcam->bundle->dev, format)
-#define gcam_info(gcam, format...)	dev_info(&gcam->bundle->dev, format)
-#define gcam_err(gcam, format...)	dev_err(&gcam->bundle->dev, format)
+#define gcam_dbg(gcam, format...)	dev_dbg(&((gcam)->bundle->dev), format)
+#define gcam_info(gcam, format...)	dev_info(&((gcam)->bundle->dev), format)
+#define gcam_err(gcam, format...)	dev_err(&((gcam)->bundle->dev), format)
  static int gb_camera_operation_sync_flags(struct gb_connection *connection,
  					  int type, unsigned int flags,

Thanks for the feedback, Alex!

I thought about refactoring it, but I feel it is worth keeping the macro around. It acts as an apdater between callers, who have 'gcam' and want to log and what the dynamic debug macros expect. Without it, the code gets pretty ugly.

Jackson

#3 lore raw
Quoted 45 lines · Jackson Chui
Quoted 28 lines · Alex Elder
Quoted 4 lines · Jackson Chui

Reported by checkpatch:

CHECK: Macro argument 'gcam' may be better as '(gcam)' to avoid precedence issues

I agree with your argument about the way the macro should be defined. But perhaps these gcam_*() functions could just be eliminated?

I see 15 calls to gcam_err(), 1 call to gcam_dbg(), and none to gcam_info(). It would be a different patch, but maybe you could do that instead?

-Alex

Quoted 11 lines

Disambiguates '&' (address-of) operator and '->' operator precedence, accounting for how '(gcam)->bundle->dev' is a 'struct device' and not a 'struct device*', which is required by the dev_{dbg,info,err} driver model diagnostic macros. Issue found by checkpatch.

---
  drivers/staging/greybus/camera.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 15 lines
Quoted 5 lines
drivers/staging/greybus/camera.c +0 -0
index a8173aa3a995..d82a2d2abdca 100644

drivers/staging/greybus/camera.c static const struct gb_camera_fmt_info *gb_camera_get_format_info(u16 gb_fmt) · line 185

Quoted 9 lines
drivers/staging/greybus/camera.c +3 -3
@@ -180,9 +180,9 @@ static const struct gb_camera_fmt_info *gb_camera_get_format_info(u16 gb_fmt)
  #define GB_CAMERA_MAX_SETTINGS_SIZE	8192
-#define gcam_dbg(gcam, format...)	dev_dbg(&gcam->bundle->dev, format)
-#define gcam_info(gcam, format...)	dev_info(&gcam->bundle->dev, format)
-#define gcam_err(gcam, format...)	dev_err(&gcam->bundle->dev, format)
+#define gcam_dbg(gcam, format...)	dev_dbg(&((gcam)->bundle->dev), format)
+#define gcam_info(gcam, format...)	dev_info(&((gcam)->bundle->dev), format)
+#define gcam_err(gcam, format...)	dev_err(&((gcam)->bundle->dev), format)
  static int gb_camera_operation_sync_flags(struct gb_connection *connection,
  					  int type, unsigned int flags,
Quoted 6 lines

Thanks for the feedback, Alex!

I thought about refactoring it, but I feel it is worth keeping the macro around. It acts as an apdater between callers, who have 'gcam' and want to log and what the dynamic debug macros expect. Without it, the code gets pretty ugly.

Another idea would be to create a function:

struct device *gcam_dev(struct gb_camera *gcam)

{
	return &gcam->bundle->dev;
}

dev_dbg(gcam_dev(gcam), "received metadata ...

(I don't know how to actually compile this code so I haven't tried it).

regards,
dan carpenter

#4 lore raw
Quoted 55 lines · Dan Carpenter
Quoted 45 lines · Jackson Chui
Quoted 28 lines · Alex Elder
Quoted 4 lines · Jackson Chui

Reported by checkpatch:

CHECK: Macro argument 'gcam' may be better as '(gcam)' to avoid precedence issues

I agree with your argument about the way the macro should be defined. But perhaps these gcam_*() functions could just be eliminated?

I see 15 calls to gcam_err(), 1 call to gcam_dbg(), and none to gcam_info(). It would be a different patch, but maybe you could do that instead?

-Alex

Quoted 11 lines

Disambiguates '&' (address-of) operator and '->' operator precedence, accounting for how '(gcam)->bundle->dev' is a 'struct device' and not a 'struct device*', which is required by the dev_{dbg,info,err} driver model diagnostic macros. Issue found by checkpatch.

---
   drivers/staging/greybus/camera.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 15 lines
Quoted 5 lines
drivers/staging/greybus/camera.c +0 -0
index a8173aa3a995..d82a2d2abdca 100644

drivers/staging/greybus/camera.c static const struct gb_camera_fmt_info *gb_camera_get_format_info(u16 gb_fmt) · line 185

Quoted 9 lines
drivers/staging/greybus/camera.c +3 -3
@@ -180,9 +180,9 @@ static const struct gb_camera_fmt_info *gb_camera_get_format_info(u16 gb_fmt)
   #define GB_CAMERA_MAX_SETTINGS_SIZE	8192
-#define gcam_dbg(gcam, format...)	dev_dbg(&gcam->bundle->dev, format)
-#define gcam_info(gcam, format...)	dev_info(&gcam->bundle->dev, format)
-#define gcam_err(gcam, format...)	dev_err(&gcam->bundle->dev, format)
+#define gcam_dbg(gcam, format...)	dev_dbg(&((gcam)->bundle->dev), format)
+#define gcam_info(gcam, format...)	dev_info(&((gcam)->bundle->dev), format)
+#define gcam_err(gcam, format...)	dev_err(&((gcam)->bundle->dev), format)
   static int gb_camera_operation_sync_flags(struct gb_connection *connection,
   					  int type, unsigned int flags,
Quoted 6 lines

Thanks for the feedback, Alex!

I thought about refactoring it, but I feel it is worth keeping the macro around. It acts as an apdater between callers, who have 'gcam' and want to log and what the dynamic debug macros expect. Without it, the code gets pretty ugly.

Another idea would be to create a function:

Quoted 8 lines

struct device *gcam_dev(struct gb_camera *gcam)

{
	return &gcam->bundle->dev;
}

dev_dbg(gcam_dev(gcam), "received metadata ...

(I don't know how to actually compile this code so I haven't tried it).

Yes, I prefer this over the original suggestion. But even here the gcam_dev() function doesn't add all that much value; it saves four characters I guess.

Jackson, the basic principle that makes me say I don't like the wrapper macros is that the wrapper obscures the simple call(s) to dev_dbg(), etc. If there was something you wanted to do every time--along with calling dev_dbg()--then maybe the wrapper would be helpful, but instead it simply hides the standard call. Better to have the code just use the functions kernel programmers recognize.

-Alex

Quoted 3 lines

regards,
dan carpenter

#5 lore raw
Quoted 78 lines · Alex Elder
Quoted 55 lines · Dan Carpenter
Quoted 45 lines · Jackson Chui
Quoted 28 lines · Alex Elder
Quoted 4 lines · Jackson Chui

Reported by checkpatch:

CHECK: Macro argument 'gcam' may be better as '(gcam)' to avoid precedence issues

I agree with your argument about the way the macro should be defined. But perhaps these gcam_*() functions could just be eliminated?

I see 15 calls to gcam_err(), 1 call to gcam_dbg(), and none to gcam_info(). It would be a different patch, but maybe you could do that instead?

-Alex

Quoted 11 lines

Disambiguates '&' (address-of) operator and '->' operator precedence, accounting for how '(gcam)->bundle->dev' is a 'struct device' and not a 'struct device*', which is required by the dev_{dbg,info,err} driver model diagnostic macros. Issue found by checkpatch.

---
   drivers/staging/greybus/camera.c | 6 +++---
   1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 15 lines
Quoted 5 lines
drivers/staging/greybus/camera.c +0 -0
index a8173aa3a995..d82a2d2abdca 100644

drivers/staging/greybus/camera.c static const struct gb_camera_fmt_info *gb_camera_get_format_info(u16 gb_fmt) · line 185

Quoted 9 lines
drivers/staging/greybus/camera.c +3 -3
@@ -180,9 +180,9 @@ static const struct gb_camera_fmt_info *gb_camera_get_format_info(u16 gb_fmt)
   #define GB_CAMERA_MAX_SETTINGS_SIZE	8192
-#define gcam_dbg(gcam, format...)	dev_dbg(&gcam->bundle->dev, format)
-#define gcam_info(gcam, format...)	dev_info(&gcam->bundle->dev, format)
-#define gcam_err(gcam, format...)	dev_err(&gcam->bundle->dev, format)
+#define gcam_dbg(gcam, format...)	dev_dbg(&((gcam)->bundle->dev), format)
+#define gcam_info(gcam, format...)	dev_info(&((gcam)->bundle->dev), format)
+#define gcam_err(gcam, format...)	dev_err(&((gcam)->bundle->dev), format)
   static int gb_camera_operation_sync_flags(struct gb_connection *connection,
   					  int type, unsigned int flags,
Quoted 6 lines

Thanks for the feedback, Alex!

I thought about refactoring it, but I feel it is worth keeping the macro around. It acts as an apdater between callers, who have 'gcam' and want to log and what the dynamic debug macros expect. Without it, the code gets pretty ugly.

Another idea would be to create a function:

Quoted 8 lines

struct device *gcam_dev(struct gb_camera *gcam)

{
	return &gcam->bundle->dev;
}

dev_dbg(gcam_dev(gcam), "received metadata ...

(I don't know how to actually compile this code so I haven't tried it).

Yes, I prefer this over the original suggestion. But even here the gcam_dev() function doesn't add all that much value; it saves four characters I guess.

Jackson, the basic principle that makes me say I don't like the wrapper macros is that the wrapper obscures the simple call(s) to dev_dbg(), etc. If there was something you wanted to do every time--along with calling dev_dbg()--then maybe the wrapper would be helpful, but instead it simply hides the standard call. Better to have the code just use the functions kernel programmers recognize.

Quoted 1 line

-Alex

Dan, Alex I think both of you are spot on.

I like the suggestion of adding 'gcam_dev()' as an accessor function and directly calling to 'dev_*'. I'm busy this weekend but will send out a new patch with this change next week.

Jackson

Quoted 4 lines
Quoted 3 lines

regards,
dan carpenter

#6 lore raw
Quoted 7 lines · Jackson Chui
Quoted 1 line

-Alex

Dan, Alex I think both of you are spot on.

I like the suggestion of adding 'gcam_dev()' as an accessor function and directly calling to 'dev_*'. I'm busy this weekend but will send out a new patch with this change next week.

Nah, don't bother with adding the gcam_dev() function. Like Alex says, it's only 4 characters shorter. Just get rid of the macros and do:

                dev_err(&gcam->bundle->dev,
                        "Unsupported unsolicited event: %u\n", op->type);

regards,
dan carpenter

#7 lore raw
In reply to Jackson Chui
Quoted 9 lines · Jackson Chui

Reported by checkpatch:

CHECK: Macro argument 'gcam' may be better as '(gcam)' to avoid precedence issues

Disambiguates '&' (address-of) operator and '->' operator precedence, accounting for how '(gcam)->bundle->dev' is a 'struct device' and not a 'struct device*', which is required by the dev_{dbg,info,err} driver model diagnostic macros. Issue found by checkpatch.

This really is not an issue at all, as you are dealing with pointers and structures and nothing else.

Quoted 11 lines
---
 drivers/staging/greybus/camera.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/staging/greybus/camera.c +0 -0
index a8173aa3a995..d82a2d2abdca 100644

drivers/staging/greybus/camera.c static const struct gb_camera_fmt_info *gb_camera_get_format_info(u16 gb_fmt) · line 183

Quoted 7 lines
drivers/staging/greybus/camera.c +1 -3
@@ -180,9 +180,9 @@ static const struct gb_camera_fmt_info *gb_camera_get_format_info(u16 gb_fmt)
 
 #define GB_CAMERA_MAX_SETTINGS_SIZE	8192
 
-#define gcam_dbg(gcam, format...)	dev_dbg(&gcam->bundle->dev, format)
-#define gcam_info(gcam, format...)	dev_info(&gcam->bundle->dev, format)
-#define gcam_err(gcam, format...)	dev_err(&gcam->bundle->dev, format)
+#define gcam_dbg(gcam, format...)	dev_dbg(&((gcam)->bundle->dev), format)

Again, the original code here is fine. Getting rid of the gcam_*() functions would be nice, as hiding dev_*() calls isn't really needed.

thanks,

greg k-h