public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/1] serial: max3100: Convert to_max3100_port() to be static inline
@ 2024-04-10 14:11 Andy Shevchenko
  2024-04-10 14:20 ` Greg Kroah-Hartman
  2024-04-11 11:20 ` Ilpo Järvinen
  0 siblings, 2 replies; 4+ messages in thread
From: Andy Shevchenko @ 2024-04-10 14:11 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Andy Shevchenko, linux-kernel, linux-serial
  Cc: Jiri Slaby

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.

Suggested-by: Jiri Slaby <jirislaby@kernel.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/tty/serial/max3100.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 1e6b5763ce3f..07ee001640bb 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -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 */
-- 
2.43.0.rc1.1.gbec44491f096


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

* Re: [PATCH v1 1/1] serial: max3100: Convert to_max3100_port() to be static inline
  2024-04-10 14:11 [PATCH v1 1/1] serial: max3100: Convert to_max3100_port() to be static inline Andy Shevchenko
@ 2024-04-10 14:20 ` Greg Kroah-Hartman
  2024-04-10 14:22   ` Andy Shevchenko
  2024-04-11 11:20 ` Ilpo Järvinen
  1 sibling, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2024-04-10 14:20 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: linux-kernel, linux-serial, Jiri Slaby

On Wed, Apr 10, 2024 at 05:11:35PM +0300, Andy Shevchenko wrote:
> 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?

> Suggested-by: Jiri Slaby <jirislaby@kernel.org>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/tty/serial/max3100.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
> index 1e6b5763ce3f..07ee001640bb 100644
> --- a/drivers/tty/serial/max3100.c
> +++ b/drivers/tty/serial/max3100.c
> @@ -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

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

* Re: [PATCH v1 1/1] serial: max3100: Convert to_max3100_port() to be static inline
  2024-04-10 14:20 ` Greg Kroah-Hartman
@ 2024-04-10 14:22   ` Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2024-04-10 14:22 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-kernel, linux-serial, Jiri Slaby

On Wed, Apr 10, 2024 at 04:20:10PM +0200, Greg Kroah-Hartman wrote:
> On Wed, Apr 10, 2024 at 05:11:35PM +0300, Andy Shevchenko wrote:
> > 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.

> 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.

...

> > -#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!

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v1 1/1] serial: max3100: Convert to_max3100_port() to be static inline
  2024-04-10 14:11 [PATCH v1 1/1] serial: max3100: Convert to_max3100_port() to be static inline Andy Shevchenko
  2024-04-10 14:20 ` Greg Kroah-Hartman
@ 2024-04-11 11:20 ` Ilpo Järvinen
  1 sibling, 0 replies; 4+ messages in thread
From: Ilpo Järvinen @ 2024-04-11 11:20 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Greg Kroah-Hartman, LKML, linux-serial, Jiri Slaby

[-- Attachment #1: Type: text/plain, Size: 1304 bytes --]

On Wed, 10 Apr 2024, Andy Shevchenko wrote:

> 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.
> 
> Suggested-by: Jiri Slaby <jirislaby@kernel.org>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/tty/serial/max3100.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
> index 1e6b5763ce3f..07ee001640bb 100644
> --- a/drivers/tty/serial/max3100.c
> +++ b/drivers/tty/serial/max3100.c
> @@ -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 */
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

It seems liteuart has the same trap.

-- 
 i.

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

end of thread, other threads:[~2024-04-11 11:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-10 14:11 [PATCH v1 1/1] serial: max3100: Convert to_max3100_port() to be static inline Andy Shevchenko
2024-04-10 14:20 ` Greg Kroah-Hartman
2024-04-10 14:22   ` Andy Shevchenko
2024-04-11 11:20 ` Ilpo Järvinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox