netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v1] sunrpc: Use ERR_CAST() to return
@ 2024-08-29 13:04 Yan Zhen
  2024-08-29 13:11 ` Jeff Layton
  2024-08-29 14:53 ` Chuck Lever
  0 siblings, 2 replies; 6+ messages in thread
From: Yan Zhen @ 2024-08-29 13:04 UTC (permalink / raw)
  To: chuck.lever, jlayton, trondmy, anna, davem, edumazet, kuba,
	pabeni
  Cc: linux-nfs, netdev, linux-kernel, opensource.kernel, neilb,
	okorniev, tom, Dai.Ngo, Yan Zhen

Using ERR_CAST() is more reasonable and safer, When it is necessary
to convert the type of an error pointer and return it.

Signed-off-by: Yan Zhen <yanzhen@vivo.com>
---
 net/sunrpc/clnt.c                        | 2 +-
 net/sunrpc/xprtrdma/svc_rdma_transport.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 09f29a95f2bc..8ee87311b348 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -603,7 +603,7 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
 
 	xprt = xprt_create_transport(&xprtargs);
 	if (IS_ERR(xprt))
-		return (struct rpc_clnt *)xprt;
+		return ERR_CAST(xprt);
 
 	/*
 	 * By default, kernel RPC client connects from a reserved port.
diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
index 581cc5ed7c0c..c3fbf0779d4a 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
@@ -369,7 +369,7 @@ static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
 	listen_id = svc_rdma_create_listen_id(net, sa, cma_xprt);
 	if (IS_ERR(listen_id)) {
 		kfree(cma_xprt);
-		return (struct svc_xprt *)listen_id;
+		return ERR_CAST(listen_id);
 	}
 	cma_xprt->sc_cm_id = listen_id;
 
-- 
2.34.1


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

* Re: [PATCH net-next v1] sunrpc: Use ERR_CAST() to return
  2024-08-29 13:04 [PATCH net-next v1] sunrpc: Use ERR_CAST() to return Yan Zhen
@ 2024-08-29 13:11 ` Jeff Layton
  2024-08-29 14:53 ` Chuck Lever
  1 sibling, 0 replies; 6+ messages in thread
From: Jeff Layton @ 2024-08-29 13:11 UTC (permalink / raw)
  To: Yan Zhen, chuck.lever, trondmy, anna, davem, edumazet, kuba,
	pabeni
  Cc: linux-nfs, netdev, linux-kernel, opensource.kernel, neilb,
	okorniev, tom, Dai.Ngo

On Thu, 2024-08-29 at 21:04 +0800, Yan Zhen wrote:
> Using ERR_CAST() is more reasonable and safer, When it is necessary
> to convert the type of an error pointer and return it.
> 
> Signed-off-by: Yan Zhen <yanzhen@vivo.com>
> ---
>  net/sunrpc/clnt.c                        | 2 +-
>  net/sunrpc/xprtrdma/svc_rdma_transport.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
> index 09f29a95f2bc..8ee87311b348 100644
> --- a/net/sunrpc/clnt.c
> +++ b/net/sunrpc/clnt.c
> @@ -603,7 +603,7 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
>  
>  	xprt = xprt_create_transport(&xprtargs);
>  	if (IS_ERR(xprt))
> -		return (struct rpc_clnt *)xprt;
> +		return ERR_CAST(xprt);
>  
>  	/*
>  	 * By default, kernel RPC client connects from a reserved port.
> diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
> index 581cc5ed7c0c..c3fbf0779d4a 100644
> --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
> +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
> @@ -369,7 +369,7 @@ static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
>  	listen_id = svc_rdma_create_listen_id(net, sa, cma_xprt);
>  	if (IS_ERR(listen_id)) {
>  		kfree(cma_xprt);
> -		return (struct svc_xprt *)listen_id;
> +		return ERR_CAST(listen_id);
>  	}
>  	cma_xprt->sc_cm_id = listen_id;
>  

Reviewed-by: Jeff Layton <jlayton@kernel.org>

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

* Re: [PATCH net-next v1] sunrpc: Use ERR_CAST() to return
  2024-08-29 13:04 [PATCH net-next v1] sunrpc: Use ERR_CAST() to return Yan Zhen
  2024-08-29 13:11 ` Jeff Layton
@ 2024-08-29 14:53 ` Chuck Lever
  1 sibling, 0 replies; 6+ messages in thread
From: Chuck Lever @ 2024-08-29 14:53 UTC (permalink / raw)
  To: Yan Zhen
  Cc: jlayton, trondmy, anna, davem, edumazet, kuba, pabeni, linux-nfs,
	netdev, linux-kernel, opensource.kernel, neilb, okorniev, tom,
	Dai.Ngo

On Thu, Aug 29, 2024 at 09:04:34PM +0800, Yan Zhen wrote:
> Using ERR_CAST() is more reasonable and safer, When it is necessary
> to convert the type of an error pointer and return it.
> 
> Signed-off-by: Yan Zhen <yanzhen@vivo.com>
> ---
>  net/sunrpc/clnt.c                        | 2 +-
>  net/sunrpc/xprtrdma/svc_rdma_transport.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
> index 09f29a95f2bc..8ee87311b348 100644
> --- a/net/sunrpc/clnt.c
> +++ b/net/sunrpc/clnt.c
> @@ -603,7 +603,7 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
>  
>  	xprt = xprt_create_transport(&xprtargs);
>  	if (IS_ERR(xprt))
> -		return (struct rpc_clnt *)xprt;
> +		return ERR_CAST(xprt);
>  
>  	/*
>  	 * By default, kernel RPC client connects from a reserved port.
> diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
> index 581cc5ed7c0c..c3fbf0779d4a 100644
> --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
> +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
> @@ -369,7 +369,7 @@ static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
>  	listen_id = svc_rdma_create_listen_id(net, sa, cma_xprt);
>  	if (IS_ERR(listen_id)) {
>  		kfree(cma_xprt);
> -		return (struct svc_xprt *)listen_id;
> +		return ERR_CAST(listen_id);
>  	}
>  	cma_xprt->sc_cm_id = listen_id;
>  
> -- 
> 2.34.1
> 
> 

These two hunks should go through separate trees, I think.

The clnt.c hunk needs to go through Anna and Trond's NFS client
tree, and the svc_rdma_transport.c hunk can go through the NFSD
tree (ie, To: me and Jeff).

Can you send two separate patches, please? The RDMA hunk looks OK to
me and I plan to apply it upon receipt of a separate patch.

-- 
Chuck Lever

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

* [PATCH net-next v1] sunrpc: Use ERR_CAST() to return
@ 2024-08-30  1:42 Yan Zhen
  2024-08-30  2:08 ` Trond Myklebust
  0 siblings, 1 reply; 6+ messages in thread
From: Yan Zhen @ 2024-08-30  1:42 UTC (permalink / raw)
  To: trondmy, anna, chuck.lever, jlayton, davem, edumazet, kuba,
	pabeni
  Cc: neilb, okorniev, Dai.Ngo, tom, linux-nfs, netdev, linux-kernel,
	opensource.kernel, Yan Zhen

Using ERR_CAST() is more reasonable and safer, When it is necessary
to convert the type of an error pointer and return it.

Signed-off-by: Yan Zhen <yanzhen@vivo.com>
---
 net/sunrpc/clnt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 09f29a95f2bc..8ee87311b348 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -603,7 +603,7 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
 
 	xprt = xprt_create_transport(&xprtargs);
 	if (IS_ERR(xprt))
-		return (struct rpc_clnt *)xprt;
+		return ERR_CAST(xprt);
 
 	/*
 	 * By default, kernel RPC client connects from a reserved port.
-- 
2.34.1


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

* Re: [PATCH net-next v1] sunrpc: Use ERR_CAST() to return
  2024-08-30  1:42 Yan Zhen
@ 2024-08-30  2:08 ` Trond Myklebust
  2024-08-30 13:39   ` Alexander Lobakin
  0 siblings, 1 reply; 6+ messages in thread
From: Trond Myklebust @ 2024-08-30  2:08 UTC (permalink / raw)
  To: davem@davemloft.net, chuck.lever@oracle.com, anna@kernel.org,
	pabeni@redhat.com, jlayton@kernel.org, edumazet@google.com,
	kuba@kernel.org, yanzhen@vivo.com
  Cc: opensource.kernel@vivo.com, okorniev@redhat.com,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	tom@talpey.com, Dai.Ngo@oracle.com, linux-nfs@vger.kernel.org,
	neilb@suse.de

On Fri, 2024-08-30 at 09:42 +0800, Yan Zhen wrote:
> Using ERR_CAST() is more reasonable and safer, When it is necessary
> to convert the type of an error pointer and return it.

static inline void * __must_check ERR_CAST(__force const void *ptr)
{
        /* cast away the const */
        return (void *) ptr;
}

That function is literally just doing an implicit cast from whatever
pointer type it is now, to a 'const void *' and then to a 'void *',
which then gets implicitly cast to whatever type the caller is
expecting. Exactly how is that "safer" than the current explicit cast?

While it is great that ERR_CAST() exists, and I agree that it should be
preferred in newer code for the (sole (!)) reason that it documents
that we expect this to be an error, I see no reason why it is
imperative to apply that change to existing code. Particularly not as a
standalone patch.

So NACK for now.


-- 
Trond Myklebust
Linux NFS client maintainer, Hammerspace
trond.myklebust@hammerspace.com



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

* Re: [PATCH net-next v1] sunrpc: Use ERR_CAST() to return
  2024-08-30  2:08 ` Trond Myklebust
@ 2024-08-30 13:39   ` Alexander Lobakin
  0 siblings, 0 replies; 6+ messages in thread
From: Alexander Lobakin @ 2024-08-30 13:39 UTC (permalink / raw)
  To: Trond Myklebust
  Cc: davem@davemloft.net, chuck.lever@oracle.com, anna@kernel.org,
	pabeni@redhat.com, jlayton@kernel.org, edumazet@google.com,
	kuba@kernel.org, yanzhen@vivo.com, opensource.kernel@vivo.com,
	okorniev@redhat.com, linux-kernel@vger.kernel.org,
	netdev@vger.kernel.org, tom@talpey.com, Dai.Ngo@oracle.com,
	linux-nfs@vger.kernel.org, neilb@suse.de

From: Trond Myklebust <trondmy@hammerspace.com>
Date: Fri, 30 Aug 2024 02:08:09 +0000

> On Fri, 2024-08-30 at 09:42 +0800, Yan Zhen wrote:
>> Using ERR_CAST() is more reasonable and safer, When it is necessary
>> to convert the type of an error pointer and return it.
> 
> static inline void * __must_check ERR_CAST(__force const void *ptr)
> {
>         /* cast away the const */
>         return (void *) ptr;
> }
> 
> That function is literally just doing an implicit cast from whatever
> pointer type it is now, to a 'const void *' and then to a 'void *',
> which then gets implicitly cast to whatever type the caller is
> expecting. Exactly how is that "safer" than the current explicit cast?

I think we might want to reimplement ERR_CAST() using _Generic() to not
cast away const when the argument itself is const.

> 
> While it is great that ERR_CAST() exists, and I agree that it should be
> preferred in newer code for the (sole (!)) reason that it documents
> that we expect this to be an error, I see no reason why it is
> imperative to apply that change to existing code. Particularly not as a
> standalone patch.
> 
> So NACK for now.

Thanks,
Olek

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

end of thread, other threads:[~2024-08-30 13:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-29 13:04 [PATCH net-next v1] sunrpc: Use ERR_CAST() to return Yan Zhen
2024-08-29 13:11 ` Jeff Layton
2024-08-29 14:53 ` Chuck Lever
  -- strict thread matches above, loose matches on Subject: below --
2024-08-30  1:42 Yan Zhen
2024-08-30  2:08 ` Trond Myklebust
2024-08-30 13:39   ` Alexander Lobakin

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