Re: [PATCH net-next v1] sunrpc: Use ERR_CAST() to return
From: Alexander Lobakin <aleksander.lobakin@intel.com>
Date: 2024-08-30 13:40:03
Also in:
linux-nfs, lkml
From: Alexander Lobakin <aleksander.lobakin@intel.com>
Date: 2024-08-30 13:40:03
Also in:
linux-nfs, lkml
From: Trond Myklebust <redacted> Date: Fri, 30 Aug 2024 02:08:09 +0000
On Fri, 2024-08-30 at 09:42 +0800, Yan Zhen wrote:quoted
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