Linux CIFS filesystem development
 help / color / mirror / Atom feed
* [PATCH] smb: client: Move an error code assignment in smb3_init_transform_rq()
@ 2025-10-08 17:04 Markus Elfring
  2025-10-08 17:17 ` Henrique Carvalho
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2025-10-08 17:04 UTC (permalink / raw)
  To: linux-cifs, samba-technical, Bharath SM, Paulo Alcantara,
	Pavel Shilovsky, Ronnie Sahlberg, Shyam Prasad N, Steve French,
	Tom Talpey
  Cc: LKML, kernel-janitors

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Wed, 8 Oct 2025 18:48:28 +0200

Convert an initialisation for the variable “rc” into an error code
assignment at the end of this function implementation.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 fs/smb/client/smb2ops.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
index 7c3e96260fd4..2513270ac596 100644
--- a/fs/smb/client/smb2ops.c
+++ b/fs/smb/client/smb2ops.c
@@ -4596,7 +4596,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
 {
 	struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
 	unsigned int orig_len = 0;
-	int rc = -ENOMEM;
+	int rc;
 
 	for (int i = 1; i < num_rqst; i++) {
 		struct smb_rqst *old = &old_rq[i - 1];
@@ -4611,7 +4611,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
 		if (size > 0) {
 			buffer = cifs_alloc_folioq_buffer(size);
 			if (!buffer)
-				goto err_free;
+				goto e_nomem;
 
 			new->rq_buffer = buffer;
 			iov_iter_folio_queue(&new->rq_iter, ITER_SOURCE,
@@ -4634,6 +4634,8 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
 
 	return rc;
 
+e_nomem:
+	rc = -ENOMEM;
 err_free:
 	smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
 	return rc;
-- 
2.51.0


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

* Re: [PATCH] smb: client: Move an error code assignment in smb3_init_transform_rq()
  2025-10-08 17:04 [PATCH] smb: client: Move an error code assignment in smb3_init_transform_rq() Markus Elfring
@ 2025-10-08 17:17 ` Henrique Carvalho
  2025-10-08 19:40   ` Markus Elfring
       [not found]   ` <CAH2r5msZjL_krwN-nd1Ly3skxAHK9srJehPJ_vYXPLRFXpJ_yw@mail.gmail.com>
  0 siblings, 2 replies; 4+ messages in thread
From: Henrique Carvalho @ 2025-10-08 17:17 UTC (permalink / raw)
  To: Markus Elfring, linux-cifs, samba-technical, Bharath SM,
	Paulo Alcantara, Pavel Shilovsky, Ronnie Sahlberg, Shyam Prasad N,
	Steve French, Tom Talpey
  Cc: LKML, kernel-janitors

Hi Markus,

On 10/8/25 2:04 PM, Markus Elfring wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Wed, 8 Oct 2025 18:48:28 +0200
> 
> Convert an initialisation for the variable “rc” into an error code
> assignment at the end of this function implementation.
> 
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
> ---
>  fs/smb/client/smb2ops.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
> index 7c3e96260fd4..2513270ac596 100644
> --- a/fs/smb/client/smb2ops.c
> +++ b/fs/smb/client/smb2ops.c
> @@ -4596,7 +4596,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
>  {
>  	struct smb2_transform_hdr *tr_hdr = new_rq[0].rq_iov[0].iov_base;
>  	unsigned int orig_len = 0;
> -	int rc = -ENOMEM;
> +	int rc;
>  
>  	for (int i = 1; i < num_rqst; i++) {
>  		struct smb_rqst *old = &old_rq[i - 1];
> @@ -4611,7 +4611,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
>  		if (size > 0) {
>  			buffer = cifs_alloc_folioq_buffer(size);
>  			if (!buffer)
> -				goto err_free;
> +				goto e_nomem;
>  
>  			new->rq_buffer = buffer;
>  			iov_iter_folio_queue(&new->rq_iter, ITER_SOURCE,
> @@ -4634,6 +4634,8 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
>  
>  	return rc;
>  
> +e_nomem:
> +	rc = -ENOMEM;
>  err_free:
>  	smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
>  	return rc;

I don't think this change improves readability.

I understand that making the assignment explicit is good, but why not
simply set rc to -ENOMEM if !buffer and then goto err_free?

Also, I think its a bit confusing having inconsistent naming styles `e_`
`err_`...

-- 
Henrique
SUSE Labs

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

* Re: [PATCH] smb: client: Move an error code assignment in smb3_init_transform_rq()
  2025-10-08 17:17 ` Henrique Carvalho
@ 2025-10-08 19:40   ` Markus Elfring
       [not found]   ` <CAH2r5msZjL_krwN-nd1Ly3skxAHK9srJehPJ_vYXPLRFXpJ_yw@mail.gmail.com>
  1 sibling, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2025-10-08 19:40 UTC (permalink / raw)
  To: Henrique Carvalho, linux-cifs, samba-technical, Bharath SM,
	Paulo Alcantara, Pavel Shilovsky, Ronnie Sahlberg, Shyam Prasad N,
	Steve French, Tom Talpey
  Cc: LKML, kernel-janitors

>> Convert an initialisation for the variable “rc” into an error code
>> assignment at the end of this function implementation.
…>> +++ b/fs/smb/client/smb2ops.c
…>> @@ -4611,7 +4611,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
>>  		if (size > 0) {
>>  			buffer = cifs_alloc_folioq_buffer(size);
>>  			if (!buffer)
>> -				goto err_free;
>> +				goto e_nomem;
>>  
>>  			new->rq_buffer = buffer;
>>  			iov_iter_folio_queue(&new->rq_iter, ITER_SOURCE,
>> @@ -4634,6 +4634,8 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
>>  
>>  	return rc;
>>  
>> +e_nomem:
>> +	rc = -ENOMEM;
>>  err_free:
>>  	smb3_free_compound_rqst(num_rqst - 1, &new_rq[1]);
>>  	return rc;
> 
> I don't think this change improves readability.
> 
> I understand that making the assignment explicit is good,

Thanks for this constructive feedback.


> but why not simply set rc to -ENOMEM if !buffer and then goto err_free?

I proposed to adjust the affected if branch in this way
because there is no need to add curly brackets then.


> Also, I think its a bit confusing having inconsistent naming styles `e_`
> `err_`...

Which naming approach would you find more helpful for the marking
of a variable assignment instead of a subsequent function call?

Regards,
Markus

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

* Re: [PATCH] smb: client: Move an error code assignment in smb3_init_transform_rq()
       [not found]   ` <CAH2r5msZjL_krwN-nd1Ly3skxAHK9srJehPJ_vYXPLRFXpJ_yw@mail.gmail.com>
@ 2025-10-08 21:00     ` Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2025-10-08 21:00 UTC (permalink / raw)
  To: Steve French, Henrique Carvalho, linux-cifs, samba-technical,
	Bharath SM, Paulo Alcantara, Pavel Shilovsky, Ronnie Sahlberg,
	Shyam Prasad N, Steve French, Tom Talpey
  Cc: LKML, kernel-janitors

> Also when a patch doesn't shrink code, but even grows it by one line, and doesn't make it much clearer, it is probably not worth changing (it complicates future backports of real fixes in the future eg). Let's limit these to those that shrink code and make code clearer (or ideally fix potential bugs)

Do you insist to keep an extra initialisation for the local variable “rc”
despite of the implementation detail that the value “-ENOMEM” is needed
only for a single if branch here?

Regards,
Markus

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

end of thread, other threads:[~2025-10-08 21:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-08 17:04 [PATCH] smb: client: Move an error code assignment in smb3_init_transform_rq() Markus Elfring
2025-10-08 17:17 ` Henrique Carvalho
2025-10-08 19:40   ` Markus Elfring
     [not found]   ` <CAH2r5msZjL_krwN-nd1Ly3skxAHK9srJehPJ_vYXPLRFXpJ_yw@mail.gmail.com>
2025-10-08 21:00     ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox