Skip to contentSkip to conversation

scsi: storvsc: Use kzfree() in storvsc_suspend()

PATCH In review Denis Efremov 4 participants 8 messages Jun 4, 2020 – Jun 10, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: storvsc: Use kzfree() in storvsc_suspend()

Use kzfree() instead of memset() with 0 followed by kfree().

---
 drivers/scsi/storvsc_drv.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/scsi/storvsc_drv.c +1 -4
index 072ed8728657..e5a19cd8a450 100644
@@ -2035,10 +2035,7 @@ static int storvsc_suspend(struct hv_device *hv_dev)
 
 	vmbus_close(hv_dev->channel);
 
-	memset(stor_device->stor_chns, 0,
-	       num_possible_cpus() * sizeof(void *));
-
-	kfree(stor_device->stor_chns);
+	kzfree(stor_device->stor_chns);
 	stor_device->stor_chns = NULL;
 
 	cpumask_clear(&stor_device->alloced_cpus);
Signature · 1 line
2.26.2
#1 lore raw
Quoted 25 lines · Denis Efremov

Use kzfree() instead of memset() with 0 followed by kfree().

---
 drivers/scsi/storvsc_drv.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/scsi/storvsc_drv.c +1 -5
index 072ed8728657..e5a19cd8a450 100644
@@ -2035,10 +2035,7 @@ static int storvsc_suspend(struct hv_device *hv_dev)
 
        vmbus_close(hv_dev->channel);
 
-       memset(stor_device->stor_chns, 0,
-              num_possible_cpus() * sizeof(void *));
-
-       kfree(stor_device->stor_chns);
+       kzfree(stor_device->stor_chns);
        stor_device->stor_chns = NULL;
 
        cpumask_clear(&stor_device->alloced_cpus);
--
Quoted 1 line

2.26.2

Hi Denis,
When I added the function storvsc_suspend() several months ago, somehow I forgot to remove the unnecessary memset(). Sorry!

The buffer is recreated in storvsc_resume() -> storvsc_connect_to_vsp() -> storvsc_channel_init() -> stor_device->stor_chns = kcalloc(...), so I believe the memset() can be safely removed. Can you please make a v2 patch for it and Cc my corporate email "decui" (in To)?

Thanks,
Dexuan

#2 lore raw
Quoted 8 lines

Hi Denis,
When I added the function storvsc_suspend() several months ago, somehow I forgot to remove the unnecessary memset(). Sorry!

The buffer is recreated in storvsc_resume() -> storvsc_connect_to_vsp() -> storvsc_channel_init() -> stor_device->stor_chns = kcalloc(...), so I believe the memset() can be safely removed.

I'm not sure that I understand your description. As for me, memset with 0 before memory freeing is required only for sensitive information and it's completely unrelated to memory zeroing during allocation with kzalloc/kcalloc. If it's not a sensitive information then memset could be safely removed.

Quoted 1 line

Can you please make a v2 patch for it and Cc my corporate email "decui" (in To)?

Yes, of course. Could I add "Suggested-by"?

Thanks,
Denis

maintainer
#3 lore raw
Quoted 11 lines

From: Denis Efremov <[email protected]>
Sent: Thursday, June 4, 2020 2:43 PM

Quoted 8 lines

Hi Denis,
When I added the function storvsc_suspend() several months ago, somehow I forgot to remove the unnecessary memset(). Sorry!

The buffer is recreated in storvsc_resume() -> storvsc_connect_to_vsp() -> storvsc_channel_init() -> stor_device->stor_chns = kcalloc(...), so I believe the memset() can be safely removed.

Quoted 5 lines

I'm not sure that I understand your description. As for me, memset with 0 before
memory freeing is required only for sensitive information and it's completely unrelated to memory zeroing during allocation with kzalloc/kcalloc. If it's not a sensitive information then memset could be safely removed.

There is no sensitive info in the buffer here.

Quoted 7 lines
Quoted 1 line

Can you please make a v2 patch for it and Cc my corporate email "decui" (in

To)?

Yes, of course. Could I add "Suggested-by"?

Thanks,
Denis

Sure.

Thanks,
-- Dexuan

maintainer
#4 lore raw
Quoted 4 lines

From: Dexuan Cui
Sent: Thursday, June 4, 2020 2:50 PM

Quoted 1 line
Quoted 1 line

Can you please make a v2 patch for it and Cc my corporate email "decui" (in

Quoted 8 lines
Quoted 6 lines

To)?

Yes, of course. Could I add "Suggested-by"?

Thanks,
Denis

Sure.

Please also added a tag:

Fixes 56fb10585934 ("scsi: storvsc: Add the support of hibernation")

Thanks,
Dexuan

#5 lore raw

PATCH 1/1 scsi: storvsc: Remove memset before memory freeing in storvsc_suspend()

In reply to Dexuan-Linux Cui

Remove memset with 0 for stor_device->stor_chns in storvsc_suspend() before the call to kfree() as the memory contains no sensitive information.

Fixes 56fb10585934 ("scsi: storvsc: Add the support of hibernation")
---
 drivers/scsi/storvsc_drv.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/scsi/storvsc_drv.c +0 -3
index 072ed8728657..2d90cddd8ac2 100644
@@ -2035,9 +2035,6 @@ static int storvsc_suspend(struct hv_device *hv_dev)
 
 	vmbus_close(hv_dev->channel);
 
-	memset(stor_device->stor_chns, 0,
-	       num_possible_cpus() * sizeof(void *));
-
 	kfree(stor_device->stor_chns);
 	stor_device->stor_chns = NULL;
 
Signature · 1 line
2.26.2
maintainer Reviewed-by on v1 1/1
#6 lore raw

RE: [PATCH] scsi: storvsc: Remove memset before memory freeing in storvsc_suspend()

Quoted 27 lines

From: Denis Efremov <[email protected]>
Sent: Friday, June 5, 2020 1:00 AM
To: Dexuan Cui <[email protected]>; Michael Kelley <[email protected]>
Cc: Denis Efremov <[email protected]>; James E . J . Bottomley <[email protected]>; Martin K . Petersen <[email protected]>; [email protected]; Linux SCSI List <[email protected]>; Linux Kernel Mailing List <[email protected]>
Subject: [PATCH] scsi: storvsc: Remove memset before memory freeing in storvsc_suspend()

Remove memset with 0 for stor_device->stor_chns in storvsc_suspend() before the call to kfree() as the memory contains no sensitive information.

Fixes 56fb10585934 ("scsi: storvsc: Add the support of hibernation")
---
 drivers/scsi/storvsc_drv.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/scsi/storvsc_drv.c +0 -0
index 072ed8728657..2d90cddd8ac2 100644
@@ -2035,9 +2035,6 @@ static int storvsc_suspend(struct hv_device
 *hv_dev)

drivers/scsi/storvsc_drv.c static int storvsc_suspend(struct hv_device

Quoted 10 lines
drivers/scsi/storvsc_drv.c +0 -4
 
 	vmbus_close(hv_dev->channel);
 
-	memset(stor_device->stor_chns, 0,
-	       num_possible_cpus() * sizeof(void *));
-
 	kfree(stor_device->stor_chns);
 	stor_device->stor_chns = NULL;
 
--

Denis, thank you for fixing this!

#7 lore raw

Re: [PATCH] scsi: storvsc: Remove memset before memory freeing in storvsc_suspend()

In reply to Denis Efremov
Quoted 2 lines · Denis Efremov

Remove memset with 0 for stor_device->stor_chns in storvsc_suspend() before the call to kfree() as the memory contains no sensitive information.

Applied to 5.8/scsi-queue, thanks!

[1/1] scsi: storvsc: Remove memset before memory freeing in storvsc_suspend()

      https://git.kernel.org/mkp/scsi/c/f47c24033a1a
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering