Skip to contentSkip to conversation

serial: max3100: Convert to_max3100_port() to be static inline

PATCH In review Andy Shevchenko 3 participants 4 messages Apr 10, 2024 – Apr 11, 2024 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: max3100: Convert to_max3100_port() to be static inline

As Jiri rightfully pointed out the current to_max3100_port() macro implementation is fragile in a sense that it expects the variable name to be port, otherwise it blow up the build.

Change this to be static inline to prevent bad compilation.

---
 drivers/tty/serial/max3100.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/tty/serial/max3100.c +4 -1
index 1e6b5763ce3f..07ee001640bb 100644
@@ -111,7 +111,10 @@ struct max3100_port {
 	struct timer_list	timer;
 };
 
-#define to_max3100_port(port)	container_of(port, struct max3100_port, port)
+static inline struct max3100_port *to_max3100_port(struct uart_port *port)
+{
+	return container_of(port, struct max3100_port, port);
+}
 
 static struct max3100_port *max3100s[MAX_MAX3100]; /* the chips */
 static DEFINE_MUTEX(max3100s_lock);		   /* race on probe */
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
#1 lore raw
Quoted 5 lines · Andy Shevchenko

As Jiri rightfully pointed out the current to_max3100_port() macro implementation is fragile in a sense that it expects the variable name to be port, otherwise it blow up the build.

Change this to be static inline to prevent bad compilation.

Is there a problem today? If not, this line isn't needed, as it sounds like you are fixing a problem here, when all you are doing is making it "nicer", right?

Quoted 11 lines
---
 drivers/tty/serial/max3100.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/tty/serial/max3100.c +0 -0
index 1e6b5763ce3f..07ee001640bb 100644

drivers/tty/serial/max3100.c struct max3100_port { · line 116

Quoted 7 lines
drivers/tty/serial/max3100.c +3 -1
@@ -111,7 +111,10 @@ struct max3100_port {
 	struct timer_list	timer;
 };
 
-#define to_max3100_port(port)	container_of(port, struct max3100_port, port)
+static inline struct max3100_port *to_max3100_port(struct uart_port *port)
+{
+	return container_of(port, struct max3100_port, port);

Note, the one reason you might want to do this as a #define is if you use container_of_const() which has to be a #define. So the fact that this was a define to start with is normal and not really a big deal.

thanks,

greg k-h

#2 lore raw
Quoted 8 lines · Greg Kroah-Hartman
Quoted 5 lines · Andy Shevchenko

As Jiri rightfully pointed out the current to_max3100_port() macro implementation is fragile in a sense that it expects the variable name to be port, otherwise it blow up the build.

Change this to be static inline to prevent bad compilation.

Is there a problem today?

Nope. And if anyone tries to make it a problem it won't build, so unlikely problematic code can ever be upstreamed.

Quoted 3 lines

If not, this line isn't needed, as it sounds
like you are fixing a problem here, when all you are doing is making it "nicer", right?

Correct.

...

Quoted 8 lines

drivers/tty/serial/max3100.c struct max3100_port { · line 116

Quoted 4 lines
drivers/tty/serial/max3100.c +3 -1
-#define to_max3100_port(port)	container_of(port, struct max3100_port, port)
+static inline struct max3100_port *to_max3100_port(struct uart_port *port)
+{
+	return container_of(port, struct max3100_port, port);

Note, the one reason you might want to do this as a #define is if you use container_of_const() which has to be a #define. So the fact that this was a define to start with is normal and not really a big deal.

Noted.

Thanks for review!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v1 1/1
#3 lore raw
In reply to Andy Shevchenko
Quoted 19 lines · Andy Shevchenko

As Jiri rightfully pointed out the current to_max3100_port() macro implementation is fragile in a sense that it expects the variable name to be port, otherwise it blow up the build.

Change this to be static inline to prevent bad compilation.

---
 drivers/tty/serial/max3100.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/tty/serial/max3100.c +0 -0
index 1e6b5763ce3f..07ee001640bb 100644
@@ -111,7 +111,10 @@ struct max3100_port {
 	struct timer_list	timer;

drivers/tty/serial/max3100.c struct max3100_port { · line 120

Quoted 10 lines
drivers/tty/serial/max3100.c +4 -1
 };
 
-#define to_max3100_port(port)	container_of(port, struct max3100_port, port)
+static inline struct max3100_port *to_max3100_port(struct uart_port *port)
+{
+	return container_of(port, struct max3100_port, port);
+}
 
 static struct max3100_port *max3100s[MAX_MAX3100]; /* the chips */
 static DEFINE_MUTEX(max3100s_lock);		   /* race on probe */

It seems liteuart has the same trap.

Signature · 1 line
 i.