diff mbox series

[v1] sfc: Convert to use ERR_CAST()

Message ID 20240828100044.53870-1-shenlichuan@vivo.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [v1] sfc: Convert to use ERR_CAST() | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
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: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
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: 16 this patch: 16
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest fail net-next-2024-08-28--12-00 (tests: 712)

Commit Message

Shen Lichuan Aug. 28, 2024, 10 a.m. UTC
As opposed to open-code, using the ERR_CAST macro clearly indicates that 
this is a pointer to an error value and a type conversion was performed.

Signed-off-by: Shen Lichuan <shenlichuan@vivo.com>
---
 drivers/net/ethernet/sfc/tc_counters.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Edward Cree Aug. 28, 2024, 1:23 p.m. UTC | #1
On 28/08/2024 11:00, Shen Lichuan wrote:
> As opposed to open-code, using the ERR_CAST macro clearly indicates that 
> this is a pointer to an error value and a type conversion was performed.
> 
> Signed-off-by: Shen Lichuan <shenlichuan@vivo.com>
> ---
>  drivers/net/ethernet/sfc/tc_counters.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/sfc/tc_counters.c b/drivers/net/ethernet/sfc/tc_counters.c
> index c44088424323..76d32641202b 100644
> --- a/drivers/net/ethernet/sfc/tc_counters.c
> +++ b/drivers/net/ethernet/sfc/tc_counters.c
> @@ -249,7 +249,7 @@ struct efx_tc_counter_index *efx_tc_flower_get_counter_index(
>  					       &ctr->linkage,
>  					       efx_tc_counter_id_ht_params);
>  			kfree(ctr);
> -			return (void *)cnt; /* it's an ERR_PTR */
> +			return ERR_CAST(cnt); /* it's an ERR_PTR */

May as well remove the now superfluous comment.
Other than that this lgtm.
Jacob Keller Aug. 28, 2024, 10:31 p.m. UTC | #2
On 8/28/2024 6:23 AM, Edward Cree wrote:
> On 28/08/2024 11:00, Shen Lichuan wrote:
>> As opposed to open-code, using the ERR_CAST macro clearly indicates that 
>> this is a pointer to an error value and a type conversion was performed.
>>
>> Signed-off-by: Shen Lichuan <shenlichuan@vivo.com>
>> ---
>>  drivers/net/ethernet/sfc/tc_counters.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/sfc/tc_counters.c b/drivers/net/ethernet/sfc/tc_counters.c
>> index c44088424323..76d32641202b 100644
>> --- a/drivers/net/ethernet/sfc/tc_counters.c
>> +++ b/drivers/net/ethernet/sfc/tc_counters.c
>> @@ -249,7 +249,7 @@ struct efx_tc_counter_index *efx_tc_flower_get_counter_index(
>>  					       &ctr->linkage,
>>  					       efx_tc_counter_id_ht_params);
>>  			kfree(ctr);

I was confused because I was wondering why you would kfree the error
value.. until I realized that this function has both "ctr" and "ctn".

>> -			return (void *)cnt; /* it's an ERR_PTR */
>> +			return ERR_CAST(cnt); /* it's an ERR_PTR */
> 
> May as well remove the now superfluous comment.
> Other than that this lgtm.
> 

Somewhat unrelated but you could cleanup some of the confusion by using
__free(kfree) annotation from <linux/cleanup.h> to avoid needing to
manually free ctr in error paths, and just use return_ptr() return the
value at the end.

Anyways, with the removal of the comment suggested by Edward,

Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Jakub Kicinski Aug. 28, 2024, 11:01 p.m. UTC | #3
On Wed, 28 Aug 2024 15:31:08 -0700 Jacob Keller wrote:
> Somewhat unrelated but you could cleanup some of the confusion by using
> __free(kfree) annotation from <linux/cleanup.h> to avoid needing to
> manually free ctr in error paths, and just use return_ptr() return the
> value at the end.

Please don't send people towards __free(). In general, but especially as
part of random cleanups.
Alejandro Lucero Palau Aug. 29, 2024, 6:47 a.m. UTC | #4
On 8/29/24 00:01, Jakub Kicinski wrote:
> On Wed, 28 Aug 2024 15:31:08 -0700 Jacob Keller wrote:
>> Somewhat unrelated but you could cleanup some of the confusion by using
>> __free(kfree) annotation from <linux/cleanup.h> to avoid needing to
>> manually free ctr in error paths, and just use return_ptr() return the
>> value at the end.
> Please don't send people towards __free(). In general, but especially as
> part of random cleanups.


Hi Kuba,


Could you explain why or point to a discussion about it?

Thanks
Jakub Kicinski Aug. 29, 2024, 3:09 p.m. UTC | #5
On Thu, 29 Aug 2024 07:47:34 +0100 Alejandro Lucero Palau wrote:
> On 8/29/24 00:01, Jakub Kicinski wrote:
> > On Wed, 28 Aug 2024 15:31:08 -0700 Jacob Keller wrote:  
> >> Somewhat unrelated but you could cleanup some of the confusion by using
> >> __free(kfree) annotation from <linux/cleanup.h> to avoid needing to
> >> manually free ctr in error paths, and just use return_ptr() return the
> >> value at the end.  
> > Please don't send people towards __free(). In general, but especially as
> > part of random cleanups.  
> 
> Could you explain why or point to a discussion about it?

It was discussed multiple times on the list and various community calls,
someone was supposed to document it but didn't. So I guess I should...
Alejandro Lucero Palau Sept. 2, 2024, 8 a.m. UTC | #6
On 8/29/24 16:09, Jakub Kicinski wrote:
> On Thu, 29 Aug 2024 07:47:34 +0100 Alejandro Lucero Palau wrote:
>> On 8/29/24 00:01, Jakub Kicinski wrote:
>>> On Wed, 28 Aug 2024 15:31:08 -0700 Jacob Keller wrote:
>>>> Somewhat unrelated but you could cleanup some of the confusion by using
>>>> __free(kfree) annotation from <linux/cleanup.h> to avoid needing to
>>>> manually free ctr in error paths, and just use return_ptr() return the
>>>> value at the end.
>>> Please don't send people towards __free(). In general, but especially as
>>> part of random cleanups.
>> Could you explain why or point to a discussion about it?
> It was discussed multiple times on the list and various community calls,
> someone was supposed to document it but didn't. So I guess I should...


I have seen your quick reaction with the cleanup.h guidance patch.

Honestly, I have never been comfortable with some of the automatic 
cleanup approaches ...


Thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/sfc/tc_counters.c b/drivers/net/ethernet/sfc/tc_counters.c
index c44088424323..76d32641202b 100644
--- a/drivers/net/ethernet/sfc/tc_counters.c
+++ b/drivers/net/ethernet/sfc/tc_counters.c
@@ -249,7 +249,7 @@  struct efx_tc_counter_index *efx_tc_flower_get_counter_index(
 					       &ctr->linkage,
 					       efx_tc_counter_id_ht_params);
 			kfree(ctr);
-			return (void *)cnt; /* it's an ERR_PTR */
+			return ERR_CAST(cnt); /* it's an ERR_PTR */
 		}
 		ctr->cnt = cnt;
 		refcount_set(&ctr->ref, 1);