linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: r8188eu: replace rtw_netdev_priv define with inline function
@ 2020-08-01  9:47 Ivan Safonov
  2020-08-01  9:51 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Ivan Safonov @ 2020-08-01  9:47 UTC (permalink / raw)
  To: Larry Finger
  Cc: Greg Kroah-Hartman, B K Karthik, Michael Straube, devel,
	linux-kernel, Ivan Safonov

The function guarantees type checking of arguments and return value.

Signed-off-by: Ivan Safonov <insafonov@gmail.com>
---
 drivers/staging/rtl8188eu/include/osdep_service.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h b/drivers/staging/rtl8188eu/include/osdep_service.h
index 31d897f1d21f..e0ccafdea9cd 100644
--- a/drivers/staging/rtl8188eu/include/osdep_service.h
+++ b/drivers/staging/rtl8188eu/include/osdep_service.h
@@ -71,8 +71,10 @@ struct rtw_netdev_priv_indicator {
 };
 struct net_device *rtw_alloc_etherdev_with_old_priv(void *old_priv);
 
-#define rtw_netdev_priv(netdev)					\
-	(((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
+static inline struct adapter *rtw_netdev_priv(struct net_device *dev)
+{
+	return (((struct rtw_netdev_priv_indicator *)netdev_priv(dev))->priv);
+}
 void rtw_free_netdev(struct net_device *netdev);
 
 #define FUNC_NDEV_FMT "%s(%s)"
-- 
2.26.2


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

* Re: [PATCH] staging: r8188eu: replace rtw_netdev_priv define with inline function
  2020-08-01  9:47 [PATCH] staging: r8188eu: replace rtw_netdev_priv define with inline function Ivan Safonov
@ 2020-08-01  9:51 ` Greg Kroah-Hartman
  2020-08-01 13:11   ` Ivan Safonov
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Kroah-Hartman @ 2020-08-01  9:51 UTC (permalink / raw)
  To: Ivan Safonov; +Cc: Larry Finger, devel, B K Karthik, linux-kernel

On Sat, Aug 01, 2020 at 12:47:07PM +0300, Ivan Safonov wrote:
> The function guarantees type checking of arguments and return value.
> 
> Signed-off-by: Ivan Safonov <insafonov@gmail.com>
> ---
>  drivers/staging/rtl8188eu/include/osdep_service.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h b/drivers/staging/rtl8188eu/include/osdep_service.h
> index 31d897f1d21f..e0ccafdea9cd 100644
> --- a/drivers/staging/rtl8188eu/include/osdep_service.h
> +++ b/drivers/staging/rtl8188eu/include/osdep_service.h
> @@ -71,8 +71,10 @@ struct rtw_netdev_priv_indicator {
>  };
>  struct net_device *rtw_alloc_etherdev_with_old_priv(void *old_priv);
>  
> -#define rtw_netdev_priv(netdev)					\
> -	(((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
> +static inline struct adapter *rtw_netdev_priv(struct net_device *dev)
> +{
> +	return (((struct rtw_netdev_priv_indicator *)netdev_priv(dev))->priv);
> +}
>  void rtw_free_netdev(struct net_device *netdev);

Is the cast really needed?

And no blank line before the next function prototype?

And is this really needed?  Type checking is already happening as this
is a "simple" macro, right?

thanks,

greg k-h

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

* Re: [PATCH] staging: r8188eu: replace rtw_netdev_priv define with inline function
  2020-08-01  9:51 ` Greg Kroah-Hartman
@ 2020-08-01 13:11   ` Ivan Safonov
  2020-08-01 13:12     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 4+ messages in thread
From: Ivan Safonov @ 2020-08-01 13:11 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Larry Finger, devel, B K Karthik, linux-kernel

On 8/1/20 12:51 PM, Greg Kroah-Hartman wrote:
> On Sat, Aug 01, 2020 at 12:47:07PM +0300, Ivan Safonov wrote:
>> The function guarantees type checking of arguments and return value.
>>
>> Signed-off-by: Ivan Safonov <insafonov@gmail.com>
>> ---
>>   drivers/staging/rtl8188eu/include/osdep_service.h | 6 ++++--
>>   1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h b/drivers/staging/rtl8188eu/include/osdep_service.h
>> index 31d897f1d21f..e0ccafdea9cd 100644
>> --- a/drivers/staging/rtl8188eu/include/osdep_service.h
>> +++ b/drivers/staging/rtl8188eu/include/osdep_service.h
>> @@ -71,8 +71,10 @@ struct rtw_netdev_priv_indicator {
>>   };
>>   struct net_device *rtw_alloc_etherdev_with_old_priv(void *old_priv);
>>   
>> -#define rtw_netdev_priv(netdev)					\
>> -	(((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
>> +static inline struct adapter *rtw_netdev_priv(struct net_device *dev)
>> +{
>> +	return (((struct rtw_netdev_priv_indicator *)netdev_priv(dev))->priv);
>> +}
>>   void rtw_free_netdev(struct net_device *netdev);
> 
> Is the cast really needed?

(struct rtw_netdev_priv_indicator *) cast needed for access to '->priv'.

The (struct adapter *) return type is a starting point for simplify
     struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
constructions.

> 
> And no blank line before the next function prototype?

In v2.

> 
> And is this really needed?  Type checking is already happening as this
> is a "simple" macro, right?

1. The flexibility of macros is not needed here.
2. The macro silently assigns ->priv to any pointer, while the function 
indicates such a compile-time error.

Ivan Safonov.

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

* Re: [PATCH] staging: r8188eu: replace rtw_netdev_priv define with inline function
  2020-08-01 13:11   ` Ivan Safonov
@ 2020-08-01 13:12     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 4+ messages in thread
From: Greg Kroah-Hartman @ 2020-08-01 13:12 UTC (permalink / raw)
  To: Ivan Safonov; +Cc: devel, B K Karthik, linux-kernel, Larry Finger

On Sat, Aug 01, 2020 at 04:11:38PM +0300, Ivan Safonov wrote:
> On 8/1/20 12:51 PM, Greg Kroah-Hartman wrote:
> > On Sat, Aug 01, 2020 at 12:47:07PM +0300, Ivan Safonov wrote:
> > > The function guarantees type checking of arguments and return value.
> > > 
> > > Signed-off-by: Ivan Safonov <insafonov@gmail.com>
> > > ---
> > >   drivers/staging/rtl8188eu/include/osdep_service.h | 6 ++++--
> > >   1 file changed, 4 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/staging/rtl8188eu/include/osdep_service.h b/drivers/staging/rtl8188eu/include/osdep_service.h
> > > index 31d897f1d21f..e0ccafdea9cd 100644
> > > --- a/drivers/staging/rtl8188eu/include/osdep_service.h
> > > +++ b/drivers/staging/rtl8188eu/include/osdep_service.h
> > > @@ -71,8 +71,10 @@ struct rtw_netdev_priv_indicator {
> > >   };
> > >   struct net_device *rtw_alloc_etherdev_with_old_priv(void *old_priv);
> > > -#define rtw_netdev_priv(netdev)					\
> > > -	(((struct rtw_netdev_priv_indicator *)netdev_priv(netdev))->priv)
> > > +static inline struct adapter *rtw_netdev_priv(struct net_device *dev)
> > > +{
> > > +	return (((struct rtw_netdev_priv_indicator *)netdev_priv(dev))->priv);
> > > +}
> > >   void rtw_free_netdev(struct net_device *netdev);
> > 
> > Is the cast really needed?
> 
> (struct rtw_netdev_priv_indicator *) cast needed for access to '->priv'.
> 
> The (struct adapter *) return type is a starting point for simplify
>     struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
> constructions.

Ah, sorry, missed that I thought this was a cast of netdev_priv(dev)
itself, and not the additional structure.

> > 
> > And no blank line before the next function prototype?
> 
> In v2.
> 
> > 
> > And is this really needed?  Type checking is already happening as this
> > is a "simple" macro, right?
> 
> 1. The flexibility of macros is not needed here.
> 2. The macro silently assigns ->priv to any pointer, while the function
> indicates such a compile-time error.

Ok, put that somewhere in the changelog please, saying how the existing
macro does not provide any error checking.

thanks,

greg k-h

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

end of thread, other threads:[~2020-08-01 13:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-01  9:47 [PATCH] staging: r8188eu: replace rtw_netdev_priv define with inline function Ivan Safonov
2020-08-01  9:51 ` Greg Kroah-Hartman
2020-08-01 13:11   ` Ivan Safonov
2020-08-01 13:12     ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).