linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] scsi: virtio_scsi: Remove unnecessary condition checks
@ 2020-07-09 17:16 Markus Elfring
  2020-07-09 17:25 ` Paolo Bonzini
  0 siblings, 1 reply; 8+ messages in thread
From: Markus Elfring @ 2020-07-09 17:16 UTC (permalink / raw)
  To: Xianting Tian, linux-scsi, virtualization
  Cc: kernel-janitors, linux-kernel, James E. J. Bottomley, Jason Wang,
	Paolo Bonzini, Martin K. Petersen, Michael S. Tsirkin,
	Stefan Hajnoczi

> kmem_cache_destroy and mempool_destroy can correctly handle
> null pointer parameter, so there is no need to check if the
> parameter is null before calling kmem_cache_destroy and
> mempool_destroy.

Can another imperative wording be preferred for the change description?


…
> +++ b/drivers/scsi/virtio_scsi.c
> @@ -1003,14 +1003,10 @@ static int __init init(void)
>  	return 0;
>
>  error:

Can such a label be questionable?


…
> +	mempool_destroy(virtscsi_cmd_pool);
> +	virtscsi_cmd_pool = NULL;
> +	kmem_cache_destroy(virtscsi_cmd_cache);
> +	virtscsi_cmd_cache = NULL;
>  	return ret;
>  }

How do you think about to add a jump target so that the execution
of a few statements can be avoided according to a previous
null pointer check?

Regards,
Markus

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

* Re: [PATCH] scsi: virtio_scsi: Remove unnecessary condition checks
  2020-07-09 17:16 [PATCH] scsi: virtio_scsi: Remove unnecessary condition checks Markus Elfring
@ 2020-07-09 17:25 ` Paolo Bonzini
  2020-07-09 20:55   ` Markus Elfring
  2020-07-10  6:32   ` Markus Elfring
  0 siblings, 2 replies; 8+ messages in thread
From: Paolo Bonzini @ 2020-07-09 17:25 UTC (permalink / raw)
  To: Markus Elfring, Xianting Tian, linux-scsi, virtualization
  Cc: kernel-janitors, linux-kernel, James E. J. Bottomley, Jason Wang,
	Martin K. Petersen, Michael S. Tsirkin, Stefan Hajnoczi

On 09/07/20 19:16, Markus Elfring wrote:
>> +	mempool_destroy(virtscsi_cmd_pool);
>> +	virtscsi_cmd_pool = NULL;
>> +	kmem_cache_destroy(virtscsi_cmd_cache);
>> +	virtscsi_cmd_cache = NULL;
>>  	return ret;
>>  }
> 
> How do you think about to add a jump target so that the execution
> of a few statements can be avoided according to a previous
> null pointer check?

The point of the patch is precisely to simplify the code, executing a
couple more instruction is not an issue.

Paolo


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

* Re: [PATCH] scsi: virtio_scsi: Remove unnecessary condition checks
  2020-07-09 17:25 ` Paolo Bonzini
@ 2020-07-09 20:55   ` Markus Elfring
  2020-07-10  6:32   ` Markus Elfring
  1 sibling, 0 replies; 8+ messages in thread
From: Markus Elfring @ 2020-07-09 20:55 UTC (permalink / raw)
  To: Paolo Bonzini, Xianting Tian, linux-scsi, virtualization
  Cc: kernel-janitors, linux-kernel, James E. J. Bottomley, Jason Wang,
	Martin K. Petersen, Michael S. Tsirkin, Stefan Hajnoczi

>>> +	mempool_destroy(virtscsi_cmd_pool);
>>> +	virtscsi_cmd_pool = NULL;
>>> +	kmem_cache_destroy(virtscsi_cmd_cache);
>>> +	virtscsi_cmd_cache = NULL;
>>>  	return ret;
>>>  }
>>
>> How do you think about to add a jump target so that the execution
>> of a few statements can be avoided according to a previous
>> null pointer check?
>
> The point of the patch is precisely to simplify the code,

I propose another bit of fine-tuning there.


> executing a couple more instruction is not an issue.

Can an additional label help here besides a possible identifier renaming?

Regards,
Markus

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

* Re: [PATCH] scsi: virtio_scsi: Remove unnecessary condition checks
  2020-07-09 17:25 ` Paolo Bonzini
  2020-07-09 20:55   ` Markus Elfring
@ 2020-07-10  6:32   ` Markus Elfring
  2020-07-10  7:17     ` Paolo Bonzini
  1 sibling, 1 reply; 8+ messages in thread
From: Markus Elfring @ 2020-07-10  6:32 UTC (permalink / raw)
  To: Paolo Bonzini, Xianting Tian, linux-scsi, virtualization
  Cc: kernel-janitors, linux-kernel, James E. J. Bottomley, Jason Wang,
	Martin K. Petersen, Michael S. Tsirkin, Stefan Hajnoczi

>>> +	mempool_destroy(virtscsi_cmd_pool);
>>> +	virtscsi_cmd_pool = NULL;
>>> +	kmem_cache_destroy(virtscsi_cmd_cache);
>>> +	virtscsi_cmd_cache = NULL;
>>>  	return ret;
>>>  }
>>
>> How do you think about to add a jump target so that the execution
>> of a few statements can be avoided according to a previous
>> null pointer check?
>
> The point of the patch is precisely to simplify the code,

I suggest to reconsider also Linux coding style aspects
for the implementation of the function “init”.
https://elixir.bootlin.com/linux/v5.8-rc4/source/drivers/scsi/virtio_scsi.c#L980
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/virtio_scsi.c?id=42f82040ee66db13525dc6f14b8559890b2f4c1c#n980

 	if (!virtscsi_cmd_cache) {
 		pr_err("kmem_cache_create() for virtscsi_cmd_cache failed\n");
-		goto error;
+		return -ENOMEM;
	}


See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=42f82040ee66db13525dc6f14b8559890b2f4c1c#n461


> executing a couple more instruction is not an issue.

With which update steps would like to achieve such a code variant?

destroy_pool:
	mempool_destroy(virtscsi_cmd_pool);
	virtscsi_cmd_pool = NULL;
destroy_cache:
	kmem_cache_destroy(virtscsi_cmd_cache);
	virtscsi_cmd_cache = NULL;
	return ret;


Regards,
Markus

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

* Re: [PATCH] scsi: virtio_scsi: Remove unnecessary condition checks
  2020-07-10  6:32   ` Markus Elfring
@ 2020-07-10  7:17     ` Paolo Bonzini
  2020-07-10  7:40       ` Markus Elfring
  0 siblings, 1 reply; 8+ messages in thread
From: Paolo Bonzini @ 2020-07-10  7:17 UTC (permalink / raw)
  To: Markus Elfring, Xianting Tian, linux-scsi, virtualization
  Cc: kernel-janitors, linux-kernel, James E. J. Bottomley, Jason Wang,
	Martin K. Petersen, Michael S. Tsirkin, Stefan Hajnoczi

On 10/07/20 08:32, Markus Elfring wrote:
>>>> +	mempool_destroy(virtscsi_cmd_pool);
>>>> +	virtscsi_cmd_pool = NULL;
>>>> +	kmem_cache_destroy(virtscsi_cmd_cache);
>>>> +	virtscsi_cmd_cache = NULL;
>>>>  	return ret;
>>>>  }
>>>
>>> How do you think about to add a jump target so that the execution
>>> of a few statements can be avoided according to a previous
>>> null pointer check?
>>
>> The point of the patch is precisely to simplify the code,
> 
> I suggest to reconsider also Linux coding style aspects
> for the implementation of the function “init”.
> https://elixir.bootlin.com/linux/v5.8-rc4/source/drivers/scsi/virtio_scsi.c#L980
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/virtio_scsi.c?id=42f82040ee66db13525dc6f14b8559890b2f4c1c#n980
> 
>  	if (!virtscsi_cmd_cache) {
>  		pr_err("kmem_cache_create() for virtscsi_cmd_cache failed\n");
> -		goto error;
> +		return -ENOMEM;
> 	}

Could be doable, but I don't see a particular benefit.  Having a single
error loop is an advantage by itself.

The coding style is a suggestion.  Note the difference between

		kfree(foo->bar);
		kfree(foo);

and

		kfree(bar);
		kfree(foo);

> See also:
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=42f82040ee66db13525dc6f14b8559890b2f4c1c#n461
> 
> 
>> executing a couple more instruction is not an issue.
> 
> With which update steps would like to achieve such a code variant?
> 
> destroy_pool:
> 	mempool_destroy(virtscsi_cmd_pool);
> 	virtscsi_cmd_pool = NULL;
> destroy_cache:
> 	kmem_cache_destroy(virtscsi_cmd_cache);
> 	virtscsi_cmd_cache = NULL;
> 	return ret;

... while there's no advantage in this.

Paolo


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

* Re: [PATCH] scsi: virtio_scsi: Remove unnecessary condition checks
  2020-07-10  7:17     ` Paolo Bonzini
@ 2020-07-10  7:40       ` Markus Elfring
  2020-07-10  7:46         ` Paolo Bonzini
  0 siblings, 1 reply; 8+ messages in thread
From: Markus Elfring @ 2020-07-10  7:40 UTC (permalink / raw)
  To: Paolo Bonzini, Xianting Tian, linux-scsi, virtualization
  Cc: kernel-janitors, linux-kernel, James E. J. Bottomley, Jason Wang,
	Martin K. Petersen, Michael S. Tsirkin, Stefan Hajnoczi

>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/virtio_scsi.c?id=42f82040ee66db13525dc6f14b8559890b2f4c1c#n980
>>
>>  	if (!virtscsi_cmd_cache) {
>>  		pr_err("kmem_cache_create() for virtscsi_cmd_cache failed\n");
>> -		goto error;
>> +		return -ENOMEM;
>>  	}
>
> Could be doable, but I don't see a particular benefit.

Can a bit more “compliance” (with the Linux coding style) matter here?


> Having a single error loop is an advantage by itself.

I do not see that a loop is involved in the implementation of the function “init”.


>> destroy_pool:
>> 	mempool_destroy(virtscsi_cmd_pool);
>> 	virtscsi_cmd_pool = NULL;
>> destroy_cache:
>> 	kmem_cache_destroy(virtscsi_cmd_cache);
>> 	virtscsi_cmd_cache = NULL;
>> 	return ret;
>
> ... while there's no advantage in this.

I propose again to improve the affected exception handling another bit
by using appropriate labels.
Will further software improvements be achieved by a corresponding patch series?

Regards,
Markus

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

* Re: [PATCH] scsi: virtio_scsi: Remove unnecessary condition checks
  2020-07-10  7:40       ` Markus Elfring
@ 2020-07-10  7:46         ` Paolo Bonzini
  2020-07-10  8:11           ` Markus Elfring
  0 siblings, 1 reply; 8+ messages in thread
From: Paolo Bonzini @ 2020-07-10  7:46 UTC (permalink / raw)
  To: Markus Elfring, Xianting Tian, linux-scsi, virtualization
  Cc: kernel-janitors, linux-kernel, James E. J. Bottomley, Jason Wang,
	Martin K. Petersen, Michael S. Tsirkin, Stefan Hajnoczi

On 10/07/20 09:40, Markus Elfring wrote:
>>> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/scsi/virtio_scsi.c?id=42f82040ee66db13525dc6f14b8559890b2f4c1c#n980
>>>
>>>  	if (!virtscsi_cmd_cache) {
>>>  		pr_err("kmem_cache_create() for virtscsi_cmd_cache failed\n");
>>> -		goto error;
>>> +		return -ENOMEM;
>>>  	}
>>
>> Could be doable, but I don't see a particular benefit.
> 
> Can a bit more “compliance” (with the Linux coding style) matter here?

No.

>> Having a single error loop is an advantage by itself.
> 
> I do not see that a loop is involved in the implementation of the function “init”.

s/loop/label/ sorry.

Paolo


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

* Re: scsi: virtio_scsi: Remove unnecessary condition checks
  2020-07-10  7:46         ` Paolo Bonzini
@ 2020-07-10  8:11           ` Markus Elfring
  0 siblings, 0 replies; 8+ messages in thread
From: Markus Elfring @ 2020-07-10  8:11 UTC (permalink / raw)
  To: Paolo Bonzini, Xianting Tian, linux-scsi, virtualization
  Cc: kernel-janitors, linux-kernel, James E. J. Bottomley, Jason Wang,
	Martin K. Petersen, Michael S. Tsirkin, Stefan Hajnoczi

>> Can a bit more “compliance” (with the Linux coding style) matter here?
>
> No.

Please take another look at the corresponding software documentation.


>>> Having a single error loop is an advantage by itself.
>>
>> I do not see that a loop is involved in the implementation of the function “init”.
>
> s/loop/label/ sorry.

Thanks for this information.

Can the development attention grow for corresponding implementation details
around the specifcation of efficient exception handling?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?id=42f82040ee66db13525dc6f14b8559890b2f4c1c#n465

Regards,
Markus

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

end of thread, other threads:[~2020-07-10  8:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-09 17:16 [PATCH] scsi: virtio_scsi: Remove unnecessary condition checks Markus Elfring
2020-07-09 17:25 ` Paolo Bonzini
2020-07-09 20:55   ` Markus Elfring
2020-07-10  6:32   ` Markus Elfring
2020-07-10  7:17     ` Paolo Bonzini
2020-07-10  7:40       ` Markus Elfring
2020-07-10  7:46         ` Paolo Bonzini
2020-07-10  8:11           ` Markus Elfring

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