diff mbox series

[net-next,v2,03/10] net: ppp: Remove unnecessary (void*) conversions

Message ID 20230710064027.173298-1-suhui@nfschina.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Remove unnecessary (void*) conversions | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1342 this patch: 1342
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 1364 this patch: 1364
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1365 this patch: 1365
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 32 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Su Hui July 10, 2023, 6:40 a.m. UTC
From: wuych <yunchuan@nfschina.com>

Pointer variables of void * type do not require type cast.

Signed-off-by: wuych <yunchuan@nfschina.com>
---
 drivers/net/ppp/pppoe.c | 4 ++--
 drivers/net/ppp/pptp.c  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Simon Horman July 11, 2023, 5:50 p.m. UTC | #1
On Mon, Jul 10, 2023 at 02:40:27PM +0800, Su Hui wrote:
> From: wuych <yunchuan@nfschina.com>
> 
> Pointer variables of void * type do not require type cast.
> 
> Signed-off-by: wuych <yunchuan@nfschina.com>
> ---
>  drivers/net/ppp/pppoe.c | 4 ++--
>  drivers/net/ppp/pptp.c  | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c
> index 3b79c603b936..ba8b6bd8233c 100644
> --- a/drivers/net/ppp/pppoe.c
> +++ b/drivers/net/ppp/pppoe.c
> @@ -968,7 +968,7 @@ static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)
>   ***********************************************************************/
>  static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb)
>  {
> -	struct sock *sk = (struct sock *)chan->private;
> +	struct sock *sk = chan->private;
>  	return __pppoe_xmit(sk, skb);
>  }
>  
> @@ -976,7 +976,7 @@ static int pppoe_fill_forward_path(struct net_device_path_ctx *ctx,
>  				   struct net_device_path *path,
>  				   const struct ppp_channel *chan)
>  {
> -	struct sock *sk = (struct sock *)chan->private;
> +	struct sock *sk = chan->private;
>  	struct pppox_sock *po = pppox_sk(sk);
>  	struct net_device *dev = po->pppoe_dev;

Hi,

Please don't break reverse xmas tree ordering - longest line to shortest -
of local variable declarations in Networking code.
Wu Yunchuan July 12, 2023, 1:44 a.m. UTC | #2
On 2023/7/12 01:50, Simon Horman wrote:
>> -	struct sock *sk = (struct sock *)chan->private;
>> +	struct sock *sk = chan->private;
>>   	struct pppox_sock *po = pppox_sk(sk);
>>   	struct net_device *dev = po->pppoe_dev;
> Hi,
>
> Please don't break reverse xmas tree ordering - longest line to shortest -
> of local variable declarations in Networking code.

Hi,

This can't be reversed because it depends on the first declaration.
Should I change it like this?

-	struct sock *sk = (struct sock *)chan->private;
- 	struct pppox_sock *po = pppox_sk(sk);
+	struct pppox_sock *po = pppox_sk(chan->private);
  	struct net_device *dev = po->pppoe_dev;
+	struct sock *sk = chan->private;

But this seems to be bad. As the advice of Andrew[1] and Dan[2]:

"

When dealing with existing broken reverse Christmas tree, please don't
make it worse with a change. But actually fixing it should be in a
different patch.

We want patches to be obviously correct. By removing the cast and
moving variables around, it is less obvious it is correct, than having
two patches.

"

Wu Yunchuan

[1] 
https://lore.kernel.org/all/23e98085-8f07-4ee2-8487-8e3b439b69f4@lunn.ch/
[2] 
https://lore.kernel.org/all/45519aec-6ec8-49e5-b5b2-1b52d336288c@kadam.mountain/
>
Simon Horman July 13, 2023, 8:41 a.m. UTC | #3
On Wed, Jul 12, 2023 at 09:44:40AM +0800, yunchuan wrote:
> On 2023/7/12 01:50, Simon Horman wrote:
> > > -	struct sock *sk = (struct sock *)chan->private;
> > > +	struct sock *sk = chan->private;
> > >   	struct pppox_sock *po = pppox_sk(sk);
> > >   	struct net_device *dev = po->pppoe_dev;
> > Hi,
> > 
> > Please don't break reverse xmas tree ordering - longest line to shortest -
> > of local variable declarations in Networking code.
> 
> Hi,
> 
> This can't be reversed because it depends on the first declaration.
> Should I change it like this?
> 
> -	struct sock *sk = (struct sock *)chan->private;
> - 	struct pppox_sock *po = pppox_sk(sk);
> +	struct pppox_sock *po = pppox_sk(chan->private);
>  	struct net_device *dev = po->pppoe_dev;
> +	struct sock *sk = chan->private;
> 
> But this seems to be bad. As the advice of Andrew[1] and Dan[2]:
> 
> "
> 
> When dealing with existing broken reverse Christmas tree, please don't
> make it worse with a change. But actually fixing it should be in a
> different patch.
> 
> We want patches to be obviously correct. By removing the cast and
> moving variables around, it is less obvious it is correct, than having
> two patches.
> 
> "

Thanks, I agree this is a good approach.
Guillaume Nault July 14, 2023, 9:07 a.m. UTC | #4
On Mon, Jul 10, 2023 at 02:40:27PM +0800, Su Hui wrote:
> From: wuych <yunchuan@nfschina.com>
> 
> Pointer variables of void * type do not require type cast.
> 
> Signed-off-by: wuych <yunchuan@nfschina.com>
> ---
>  drivers/net/ppp/pppoe.c | 4 ++--
>  drivers/net/ppp/pptp.c  | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)

Reviewed-by: Guillaume Nault <gnault@redhat.com>

While there, you might want to also remove the useless casts in
net/l2tp/l2tp_ppp.c and net/atm/pppoatm.c.

> diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c
> index 3b79c603b936..ba8b6bd8233c 100644
> --- a/drivers/net/ppp/pppoe.c
> +++ b/drivers/net/ppp/pppoe.c
> @@ -968,7 +968,7 @@ static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)
>   ***********************************************************************/
>  static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb)
>  {
> -	struct sock *sk = (struct sock *)chan->private;
> +	struct sock *sk = chan->private;
>  	return __pppoe_xmit(sk, skb);
>  }
>  
> @@ -976,7 +976,7 @@ static int pppoe_fill_forward_path(struct net_device_path_ctx *ctx,
>  				   struct net_device_path *path,
>  				   const struct ppp_channel *chan)
>  {
> -	struct sock *sk = (struct sock *)chan->private;
> +	struct sock *sk = chan->private;
>  	struct pppox_sock *po = pppox_sk(sk);
>  	struct net_device *dev = po->pppoe_dev;
>  
> diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c
> index 32183f24e63f..6b3d3df99549 100644
> --- a/drivers/net/ppp/pptp.c
> +++ b/drivers/net/ppp/pptp.c
> @@ -148,7 +148,7 @@ static struct rtable *pptp_route_output(struct pppox_sock *po,
>  
>  static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
>  {
> -	struct sock *sk = (struct sock *) chan->private;
> +	struct sock *sk = chan->private;
>  	struct pppox_sock *po = pppox_sk(sk);
>  	struct net *net = sock_net(sk);
>  	struct pptp_opt *opt = &po->proto.pptp;
> @@ -575,7 +575,7 @@ static int pptp_create(struct net *net, struct socket *sock, int kern)
>  static int pptp_ppp_ioctl(struct ppp_channel *chan, unsigned int cmd,
>  	unsigned long arg)
>  {
> -	struct sock *sk = (struct sock *) chan->private;
> +	struct sock *sk = chan->private;
>  	struct pppox_sock *po = pppox_sk(sk);
>  	struct pptp_opt *opt = &po->proto.pptp;
>  	void __user *argp = (void __user *)arg;
> -- 
> 2.30.2
> 
>
Wu Yunchuan July 17, 2023, 1:33 a.m. UTC | #5
On 2023/7/14 17:07, Guillaume Nault wrote:
> On Mon, Jul 10, 2023 at 02:40:27PM +0800, Su Hui wrote:
>> From: wuych <yunchuan@nfschina.com>
>>
>> Pointer variables of void * type do not require type cast.
>>
>> Signed-off-by: wuych <yunchuan@nfschina.com>
>> ---
>>   drivers/net/ppp/pppoe.c | 4 ++--
>>   drivers/net/ppp/pptp.c  | 4 ++--
>>   2 files changed, 4 insertions(+), 4 deletions(-)
> Reviewed-by: Guillaume Nault <gnault@redhat.com>
>
> While there, you might want to also remove the useless casts in
> net/l2tp/l2tp_ppp.c and net/atm/pppoatm.c.

Hi,

Thanks four your reminder! There are about 20 useless casts in net.
I will remove all of them.

Wu Yunchuan

>> diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c
>> index 3b79c603b936..ba8b6bd8233c 100644
>> --- a/drivers/net/ppp/pppoe.c
>> +++ b/drivers/net/ppp/pppoe.c
>> @@ -968,7 +968,7 @@ static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)
>>    ***********************************************************************/
>>   static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb)
>>   {
>> -	struct sock *sk = (struct sock *)chan->private;
>> +	struct sock *sk = chan->private;
>>   	return __pppoe_xmit(sk, skb);
>>   }
>>   
>> @@ -976,7 +976,7 @@ static int pppoe_fill_forward_path(struct net_device_path_ctx *ctx,
>>   				   struct net_device_path *path,
>>   				   const struct ppp_channel *chan)
>>   {
>> -	struct sock *sk = (struct sock *)chan->private;
>> +	struct sock *sk = chan->private;
>>   	struct pppox_sock *po = pppox_sk(sk);
>>   	struct net_device *dev = po->pppoe_dev;
>>   
>> diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c
>> index 32183f24e63f..6b3d3df99549 100644
>> --- a/drivers/net/ppp/pptp.c
>> +++ b/drivers/net/ppp/pptp.c
>> @@ -148,7 +148,7 @@ static struct rtable *pptp_route_output(struct pppox_sock *po,
>>   
>>   static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
>>   {
>> -	struct sock *sk = (struct sock *) chan->private;
>> +	struct sock *sk = chan->private;
>>   	struct pppox_sock *po = pppox_sk(sk);
>>   	struct net *net = sock_net(sk);
>>   	struct pptp_opt *opt = &po->proto.pptp;
>> @@ -575,7 +575,7 @@ static int pptp_create(struct net *net, struct socket *sock, int kern)
>>   static int pptp_ppp_ioctl(struct ppp_channel *chan, unsigned int cmd,
>>   	unsigned long arg)
>>   {
>> -	struct sock *sk = (struct sock *) chan->private;
>> +	struct sock *sk = chan->private;
>>   	struct pppox_sock *po = pppox_sk(sk);
>>   	struct pptp_opt *opt = &po->proto.pptp;
>>   	void __user *argp = (void __user *)arg;
>> -- 
>> 2.30.2
>>
>>
Guillaume Nault July 17, 2023, 1:21 p.m. UTC | #6
On Mon, Jul 17, 2023 at 09:33:30AM +0800, yunchuan wrote:
> On 2023/7/14 17:07, Guillaume Nault wrote:
> > On Mon, Jul 10, 2023 at 02:40:27PM +0800, Su Hui wrote:
> > > From: wuych <yunchuan@nfschina.com>
> > > 
> > > Pointer variables of void * type do not require type cast.
> > > 
> > > Signed-off-by: wuych <yunchuan@nfschina.com>
> > > ---
> > >   drivers/net/ppp/pppoe.c | 4 ++--
> > >   drivers/net/ppp/pptp.c  | 4 ++--
> > >   2 files changed, 4 insertions(+), 4 deletions(-)
> > Reviewed-by: Guillaume Nault <gnault@redhat.com>
> > 
> > While there, you might want to also remove the useless casts in
> > net/l2tp/l2tp_ppp.c and net/atm/pppoatm.c.
> 
> Hi,
> 
> Thanks four your reminder! There are about 20 useless casts in net.
> I will remove all of them.

I was specifically pointing at l2tp_ppp.c and pppoatm.c because they
convert the same kind of variable (chan->private) and cound be sqashed
into this commit.

But if you prefer to handle these separately, that's obviously fine too.

> Wu Yunchuan
> 
> > > diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c
> > > index 3b79c603b936..ba8b6bd8233c 100644
> > > --- a/drivers/net/ppp/pppoe.c
> > > +++ b/drivers/net/ppp/pppoe.c
> > > @@ -968,7 +968,7 @@ static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)
> > >    ***********************************************************************/
> > >   static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb)
> > >   {
> > > -	struct sock *sk = (struct sock *)chan->private;
> > > +	struct sock *sk = chan->private;
> > >   	return __pppoe_xmit(sk, skb);
> > >   }
> > > @@ -976,7 +976,7 @@ static int pppoe_fill_forward_path(struct net_device_path_ctx *ctx,
> > >   				   struct net_device_path *path,
> > >   				   const struct ppp_channel *chan)
> > >   {
> > > -	struct sock *sk = (struct sock *)chan->private;
> > > +	struct sock *sk = chan->private;
> > >   	struct pppox_sock *po = pppox_sk(sk);
> > >   	struct net_device *dev = po->pppoe_dev;
> > > diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c
> > > index 32183f24e63f..6b3d3df99549 100644
> > > --- a/drivers/net/ppp/pptp.c
> > > +++ b/drivers/net/ppp/pptp.c
> > > @@ -148,7 +148,7 @@ static struct rtable *pptp_route_output(struct pppox_sock *po,
> > >   static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
> > >   {
> > > -	struct sock *sk = (struct sock *) chan->private;
> > > +	struct sock *sk = chan->private;
> > >   	struct pppox_sock *po = pppox_sk(sk);
> > >   	struct net *net = sock_net(sk);
> > >   	struct pptp_opt *opt = &po->proto.pptp;
> > > @@ -575,7 +575,7 @@ static int pptp_create(struct net *net, struct socket *sock, int kern)
> > >   static int pptp_ppp_ioctl(struct ppp_channel *chan, unsigned int cmd,
> > >   	unsigned long arg)
> > >   {
> > > -	struct sock *sk = (struct sock *) chan->private;
> > > +	struct sock *sk = chan->private;
> > >   	struct pppox_sock *po = pppox_sk(sk);
> > >   	struct pptp_opt *opt = &po->proto.pptp;
> > >   	void __user *argp = (void __user *)arg;
> > > -- 
> > > 2.30.2
> > > 
> > > 
>
diff mbox series

Patch

diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c
index 3b79c603b936..ba8b6bd8233c 100644
--- a/drivers/net/ppp/pppoe.c
+++ b/drivers/net/ppp/pppoe.c
@@ -968,7 +968,7 @@  static int __pppoe_xmit(struct sock *sk, struct sk_buff *skb)
  ***********************************************************************/
 static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb)
 {
-	struct sock *sk = (struct sock *)chan->private;
+	struct sock *sk = chan->private;
 	return __pppoe_xmit(sk, skb);
 }
 
@@ -976,7 +976,7 @@  static int pppoe_fill_forward_path(struct net_device_path_ctx *ctx,
 				   struct net_device_path *path,
 				   const struct ppp_channel *chan)
 {
-	struct sock *sk = (struct sock *)chan->private;
+	struct sock *sk = chan->private;
 	struct pppox_sock *po = pppox_sk(sk);
 	struct net_device *dev = po->pppoe_dev;
 
diff --git a/drivers/net/ppp/pptp.c b/drivers/net/ppp/pptp.c
index 32183f24e63f..6b3d3df99549 100644
--- a/drivers/net/ppp/pptp.c
+++ b/drivers/net/ppp/pptp.c
@@ -148,7 +148,7 @@  static struct rtable *pptp_route_output(struct pppox_sock *po,
 
 static int pptp_xmit(struct ppp_channel *chan, struct sk_buff *skb)
 {
-	struct sock *sk = (struct sock *) chan->private;
+	struct sock *sk = chan->private;
 	struct pppox_sock *po = pppox_sk(sk);
 	struct net *net = sock_net(sk);
 	struct pptp_opt *opt = &po->proto.pptp;
@@ -575,7 +575,7 @@  static int pptp_create(struct net *net, struct socket *sock, int kern)
 static int pptp_ppp_ioctl(struct ppp_channel *chan, unsigned int cmd,
 	unsigned long arg)
 {
-	struct sock *sk = (struct sock *) chan->private;
+	struct sock *sk = chan->private;
 	struct pppox_sock *po = pppox_sk(sk);
 	struct pptp_opt *opt = &po->proto.pptp;
 	void __user *argp = (void __user *)arg;