Staging: panel: Fixed a macro coding style issue
PATCH 1/1 Staging: panel: Fixed a macro coding style issue
Removed do {} while (0) loop for a single statement macros
--- linux-3.6-rc6/drivers/staging/panel/panel.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
linux-3.6-rc6/drivers/staging/panel/panel.c +2 -2
@@ -137,8 +137,8 @@#define r_ctr (x) (parport_read_control((x)->port))#define r_dtr (x) (parport_read_data((x)->port))#define r_str (x) (parport_read_status((x)->port)) -#define w_ctr (x, y) do { parport_write_control((x)->port, (y)); } while (0) -#define w_dtr (x, y) do { parport_write_data((x)->port, (y)); } while (0) +#define w_ctr (x, y) (parport_write_control((x)->port, (y))) +#define w_dtr (x, y) (parport_write_data((x)->port, (y)))/* this defines which bits are to be used and which ones to be ignored */ /* logical or of the output bits involved in the scan matrix */
Signature · 1 line
1.7.7.3
Quoted 12 lines · Adil Mujeeb
Removed do {} while (0) loop for a single statement macros
Signed-off-by Adil Mujeeb <[email protected]>--- linux-3.6-rc6/drivers/staging/panel/panel.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)linux-3.6-rc6/drivers/staging/panel/panel.c +0
-0
linux-3.6-rc6/drivers/staging/panel/panel.c line 141
Quoted 7 lines
linux-3.6-rc6/drivers/staging/panel/panel.c +2
-2@@ -137,8 +137,8 @@#define r_ctr (x) (parport_read_control((x)->port))#define r_dtr (x) (parport_read_data((x)->port))#define r_str (x) (parport_read_status((x)->port)) -#define w_ctr (x, y) do { parport_write_control((x)->port, (y)); } while (0) -#define w_dtr (x, y) do { parport_write_data((x)->port, (y)); } while (0) +#define w_ctr (x, y) (parport_write_control((x)->port, (y))) +#define w_dtr (x, y) (parport_write_data((x)->port, (y)))
Unnecessary parentheses too.
It might be better to use static inlines instead.
Quoted 8 lines · Joe Perches
Quoted 7 lines · Adil Mujeeb
Removed do {} while (0) loop for a single statement macros
Signed-off-by Adil Mujeeb <[email protected]>--- linux-3.6-rc6/drivers/staging/panel/panel.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
Quoted 15 lines
linux-3.6-rc6/drivers/staging/panel/panel.c line 141
Quoted 12 lines
linux-3.6-rc6/drivers/staging/panel/panel.c +2
-2@@ -137,8 +137,8 @@#define r_ctr (x) (parport_read_control((x)->port))#define r_dtr (x) (parport_read_data((x)->port))#define r_str (x) (parport_read_status((x)->port)) -#define w_ctr (x, y) do { parport_write_control((x)->port, (y)); } while (0) -#define w_dtr (x, y) do { parport_write_data((x)->port, (y)); } while (0) +#define w_ctr (x, y) (parport_write_control((x)->port, (y))) +#define w_dtr (x, y) (parport_write_data((x)->port, (y)))Unnecessary parentheses too.
It might be better to use static inlines instead.
Agreed. We already got bugs in the cyrix register manipulation for years because of the use of macros which caused registers to be set in the wrong order, let's not redo that mistake again.
Willy
Quoted 9 lines · Willy Tarreau
Quoted 8 lines · Joe Perches
Quoted 7 lines · Adil Mujeeb
Removed do {} while (0) loop for a single statement macros
Signed-off-by Adil Mujeeb <[email protected]>--- linux-3.6-rc6/drivers/staging/panel/panel.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
linux-3.6-rc6/drivers/staging/panel/panel.c +0
-0@@ -137,8 +137,8 @@#define r_ctr (x) (parport_read_control((x)->port))#define r_dtr (x) (parport_read_data((x)->port))Quoted 8 lines
linux-3.6-rc6/drivers/staging/panel/panel.c line 141
Quoted 5 lines
linux-3.6-rc6/drivers/staging/panel/panel.c +2
-2#define r_str (x) (parport_read_status((x)->port)) -#define w_ctr (x, y) do { parport_write_control((x)->port, (y)); } while (0) -#define w_dtr (x, y) do { parport_write_data((x)->port, (y)); } while (0) +#define w_ctr (x, y) (parport_write_control((x)->port, (y))) +#define w_dtr (x, y) (parport_write_data((x)->port, (y)))Unnecessary parentheses too.
It might be better to use static inlines instead.
I just did this change only as per checkpatch script warning. Also the parentheses is added similar to other macros.
So should i removed all the macros and convert it to static inlines ?
Quoted 3 lines
Agreed. We already got bugs in the cyrix register manipulation for years because of the use of macros which caused registers to be set in the wrong order, let's not redo that mistake again.
hmmm macros seems too dangerous but does it mean we should not use macros altogether?
So should i create a single patch which replaces all macros of this file into inline function?
This is my first effort in submitting a patch :)
PS: I have correct the email id from [email protected] to [email protected]. My mistake while submitting the patch in first post :(
Quoted 3 lines
Willy
Quoted 30 lines · Adil Mujeeb
Quoted 9 lines · Willy Tarreau
Quoted 8 lines · Joe Perches
Quoted 7 lines · Adil Mujeeb
Removed do {} while (0) loop for a single statement macros
Signed-off-by Adil Mujeeb <[email protected]>--- linux-3.6-rc6/drivers/staging/panel/panel.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
linux-3.6-rc6/drivers/staging/panel/panel.c +0
-0@@ -137,8 +137,8 @@#define r_ctr (x) (parport_read_control((x)->port))#define r_dtr (x) (parport_read_data((x)->port))Quoted 8 lines
linux-3.6-rc6/drivers/staging/panel/panel.c line 141
Quoted 5 lines
linux-3.6-rc6/drivers/staging/panel/panel.c +2
-2#define r_str (x) (parport_read_status((x)->port)) -#define w_ctr (x, y) do { parport_write_control((x)->port, (y)); } while (0) -#define w_dtr (x, y) do { parport_write_data((x)->port, (y)); } while (0) +#define w_ctr (x, y) (parport_write_control((x)->port, (y))) +#define w_dtr (x, y) (parport_write_data((x)->port, (y)))Unnecessary parentheses too.
It might be better to use static inlines instead.I just did this change only as per checkpatch script warning. Also the parentheses is added similar to other macros.
So should i removed all the macros and convert it to static inlines ?
Quoted 6 lines
Quoted 3 lines
Agreed. We already got bugs in the cyrix register manipulation for years because of the use of macros which caused registers to be set in the wrong order, let's not redo that mistake again.
hmmm macros seems too dangerous but does it mean we should not use macros altogether?
As long as we can easily replace them with static inline, we should avoid them. They're pretty useful for many things (eg: type-agnostic data manipulation) but what you see above does not provide much value in my opinion. And I wrote this something like 10 years ago but since then I learned from my mistakes :-)
Quoted 2 lines
So should i create a single patch which replaces all macros of this file into inline function?
It might be possible, but what are you trying to do ? If it's just a minor cleanup patch, there is always the risk of breaking something for zero value added. This driver needs a major lifting, it needs to be cut into smaller functions for example. Maybe this is something you should try to do instead of just changing a few defines ?
Also, do you have such a device to test your changes ?
Quoted 1 line
This is my first effort in submitting a patch :)
You're welcome in this effort, but you should be very careful. Playing with driver code is fun and addictive, but that breaks much faster than you can imagine and it becomes frustrating to see your cleanup patch reverted two days after its inclusion.
Regards,
Willy
Hi,
Quoted 35 lines · Willy Tarreau
Quoted 34 lines · Adil Mujeeb
Quoted 9 lines · Willy Tarreau
Quoted 8 lines · Joe Perches
Quoted 7 lines · Adil Mujeeb
Removed do {} while (0) loop for a single statement macros
Signed-off-by Adil Mujeeb <[email protected]>--- linux-3.6-rc6/drivers/staging/panel/panel.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)Quoted 15 lines
Quoted 7 lines
Quoted 7 lines
linux-3.6-rc6/drivers/staging/panel/panel.c +0
-0@@ -137,8 +137,8 @@#define r_ctr (x) (parport_read_control((x)->port))#define r_dtr (x) (parport_read_data((x)->port))Quoted 8 lines
linux-3.6-rc6/drivers/staging/panel/panel.c line 141
Quoted 5 lines
linux-3.6-rc6/drivers/staging/panel/panel.c +2
-2#define r_str (x) (parport_read_status((x)->port)) -#define w_ctr (x, y) do { parport_write_control((x)->port, (y)); } while (0) -#define w_dtr (x, y) do { parport_write_data((x)->port, (y)); } while (0) +#define w_ctr (x, y) (parport_write_control((x)->port, (y))) +#define w_dtr (x, y) (parport_write_data((x)->port, (y)))Unnecessary parentheses too.
It might be better to use static inlines instead.I just did this change only as per checkpatch script warning. Also the parentheses is added similar to other macros.
So should i removed all the macros and convert it to static inlines ?Quoted 3 lines
Agreed. We already got bugs in the cyrix register manipulation for years because of the use of macros which caused registers to be set in the wrong order, let's not redo that mistake again.
Quoted 8 lines
Quoted 2 lines
hmmm macros seems too dangerous but does it mean we should not use macros altogether?
As long as we can easily replace them with static inline, we should avoid them. They're pretty useful for many things (eg: type-agnostic data manipulation) but what you see above does not provide much value in my opinion. And I wrote this something like 10 years ago but since then I learned from my mistakes :-)
Thanks for sharing :)
Quoted 8 lines
Quoted 2 lines
So should i create a single patch which replaces all macros of this file into inline function?
It might be possible, but what are you trying to do ? If it's just a minor cleanup patch, there is always the risk of breaking something for zero value added. This driver needs a major lifting, it needs to be cut into smaller functions for example. Maybe this is something you should try to do instead of just changing a few defines ?
Yes I was just doing minor cleanup and one of TODO item.
Quoted 1 line
Also, do you have such a device to test your changes ?
No I dont have.
Quoted 6 lines
Quoted 1 line
This is my first effort in submitting a patch :)
You're welcome in this effort, but you should be very careful. Playing with driver code is fun and addictive, but that breaks much faster than you can imagine and it becomes frustrating to see your cleanup patch reverted two days after its inclusion.
Thanks for advice, I'll keep this in mind while doing the changes next time :)
Regards,
Adil
Quoted 4 lines
Regards,
Willy