[PATCH] cxl: Slightly simplify emit_target_list()

Christophe JAILLET posted 1 patch 1 month, 2 weeks ago
drivers/cxl/core/port.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
[PATCH] cxl: Slightly simplify emit_target_list()
Posted by Christophe JAILLET 1 month, 2 weeks ago
sysfs_emit_at() never returns a negative error code. It returns 0 or the
number of characters written in the buffer.

Remove the useless test. This simplifies the logic and saves a few lines of
code.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/cxl/core/port.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
index fef3aa0c6680..b77c1600beaa 100644
--- a/drivers/cxl/core/port.c
+++ b/drivers/cxl/core/port.c
@@ -151,7 +151,7 @@ static ssize_t emit_target_list(struct cxl_switch_decoder *cxlsd, char *buf)
 {
 	struct cxl_decoder *cxld = &cxlsd->cxld;
 	ssize_t offset = 0;
-	int i, rc = 0;
+	int i;
 
 	for (i = 0; i < cxld->interleave_ways; i++) {
 		struct cxl_dport *dport = cxlsd->target[i];
@@ -162,11 +162,9 @@ static ssize_t emit_target_list(struct cxl_switch_decoder *cxlsd, char *buf)
 
 		if (i + 1 < cxld->interleave_ways)
 			next = cxlsd->target[i + 1];
-		rc = sysfs_emit_at(buf, offset, "%d%s", dport->port_id,
-				   next ? "," : "");
-		if (rc < 0)
-			return rc;
-		offset += rc;
+		offset += sysfs_emit_at(buf, offset, "%d%s",
+					dport->port_id,
+					next ? "," : "");
 	}
 
 	return offset;
-- 
2.52.0
Re: [PATCH] cxl: Slightly simplify emit_target_list()
Posted by Alison Schofield 1 month, 2 weeks ago
On Sun, Dec 21, 2025 at 03:15:04PM +0100, Christophe JAILLET wrote:
> sysfs_emit_at() never returns a negative error code. It returns 0 or the
> number of characters written in the buffer.
> 
> Remove the useless test. This simplifies the logic and saves a few lines of
> code.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/cxl/core/port.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
> index fef3aa0c6680..b77c1600beaa 100644
> --- a/drivers/cxl/core/port.c
> +++ b/drivers/cxl/core/port.c
> @@ -151,7 +151,7 @@ static ssize_t emit_target_list(struct cxl_switch_decoder *cxlsd, char *buf)
>  {
>  	struct cxl_decoder *cxld = &cxlsd->cxld;
>  	ssize_t offset = 0;
> -	int i, rc = 0;
> +	int i;
>  
>  	for (i = 0; i < cxld->interleave_ways; i++) {
>  		struct cxl_dport *dport = cxlsd->target[i];
> @@ -162,11 +162,9 @@ static ssize_t emit_target_list(struct cxl_switch_decoder *cxlsd, char *buf)
>  
>  		if (i + 1 < cxld->interleave_ways)
>  			next = cxlsd->target[i + 1];
> -		rc = sysfs_emit_at(buf, offset, "%d%s", dport->port_id,
> -				   next ? "," : "");
> -		if (rc < 0)
> -			return rc;
> -		offset += rc;
> +		offset += sysfs_emit_at(buf, offset, "%d%s",
> +					dport->port_id,
> +					next ? "," : "");
>  	}
>  
>  	return offset;

Can this can be cleaned up further at the target_list_show() call
site which also checks for an impossible rc < 0 (twice).



> -- 
> 2.52.0
>
Re: [PATCH] cxl: Slightly simplify emit_target_list()
Posted by Christophe JAILLET 1 month, 2 weeks ago
Le 22/12/2025 à 04:52, Alison Schofield a écrit :
> On Sun, Dec 21, 2025 at 03:15:04PM +0100, Christophe JAILLET wrote:
>> sysfs_emit_at() never returns a negative error code. It returns 0 or the
>> number of characters written in the buffer.
>>
>> Remove the useless test. This simplifies the logic and saves a few lines of
>> code.
>>
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>>   drivers/cxl/core/port.c | 10 ++++------
>>   1 file changed, 4 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c
>> index fef3aa0c6680..b77c1600beaa 100644
>> --- a/drivers/cxl/core/port.c
>> +++ b/drivers/cxl/core/port.c
>> @@ -151,7 +151,7 @@ static ssize_t emit_target_list(struct cxl_switch_decoder *cxlsd, char *buf)
>>   {
>>   	struct cxl_decoder *cxld = &cxlsd->cxld;
>>   	ssize_t offset = 0;
>> -	int i, rc = 0;
>> +	int i;
>>   
>>   	for (i = 0; i < cxld->interleave_ways; i++) {
>>   		struct cxl_dport *dport = cxlsd->target[i];
>> @@ -162,11 +162,9 @@ static ssize_t emit_target_list(struct cxl_switch_decoder *cxlsd, char *buf)
>>   
>>   		if (i + 1 < cxld->interleave_ways)
>>   			next = cxlsd->target[i + 1];
>> -		rc = sysfs_emit_at(buf, offset, "%d%s", dport->port_id,
>> -				   next ? "," : "");
>> -		if (rc < 0)
>> -			return rc;
>> -		offset += rc;
>> +		offset += sysfs_emit_at(buf, offset, "%d%s",
>> +					dport->port_id,
>> +					next ? "," : "");
>>   	}
>>   
>>   	return offset;
> 
> Can this can be cleaned up further at the target_list_show() call
> site which also checks for an impossible rc < 0 (twice).

I missed that, sorry.

target_list_show() only add a guard() and a trailing \n.
Maybe, both function could be merged.

Is it ok for you  this way ?

CJ

> 
> 
> 
>> -- 
>> 2.52.0
>>
> 
>