Skip to contentSkip to conversation

Check whether divisor is non-zero before division

PATCH Superseded Shichao Lai 3 participants 5 messages May 23, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Check whether divisor is non-zero before division

Since uzonesize may be zero, so a judgement for non-zero is nessesary.

---
 drivers/usb/storage/alauda.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/storage/alauda.c +2 -0
index 115f05a6201a..db075a8c03cb 100644
@@ -947,6 +947,8 @@ static int alauda_read_data(struct us_data *us, unsigned long address,
 	sg = NULL;
 
 	while (sectors > 0) {
+		if (!uzonesize)
+			return USB_STOR_TRANSPORT_ERROR;
 		unsigned int zone = lba / uzonesize; /* integer division */
 		unsigned int lba_offset = lba - (zone * uzonesize);
 		unsigned int pages;
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 26 lines · Shichao Lai

Since uzonesize may be zero, so a judgement for non-zero is nessesary.

---
 drivers/usb/storage/alauda.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/storage/alauda.c +2 -0
index 115f05a6201a..db075a8c03cb 100644
@@ -947,6 +947,8 @@ static int alauda_read_data(struct us_data *us, unsigned long address,
 	sg = NULL;
 
 	while (sectors > 0) {
+		if (!uzonesize)
+			return USB_STOR_TRANSPORT_ERROR;
 		unsigned int zone = lba / uzonesize; /* integer division */
 		unsigned int lba_offset = lba - (zone * uzonesize);
 		unsigned int pages;
Signature · 1 line
2.34.1

Looks good, thanks! I'll queue this up after 6.10-rc1 is out.

greg k-h

#2 lore raw
In reply to Shichao Lai

On 23.05.24 09:22, Shichao Lai wrote:

Hi,

Quoted 14 lines

Since uzonesize may be zero, so a judgement for non-zero is nessesary.

---
  drivers/usb/storage/alauda.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/usb/storage/alauda.c +0 -0
index 115f05a6201a..db075a8c03cb 100644

drivers/usb/storage/alauda.c static int alauda_read_data(struct us_data *us, unsigned long address, · line 951

Quoted 5 lines
drivers/usb/storage/alauda.c +2 -0
@@ -947,6 +947,8 @@ static int alauda_read_data(struct us_data *us, unsigned long address,
  	sg = NULL;
 
  	while (sectors > 0) {
+		if (!uzonesize)
+			return USB_STOR_TRANSPORT_ERROR;

May I point out that uzonesize does not change in this function? There is no need to retest within the loop.

drivers/usb/storage/alauda.c static int alauda_read_data(struct us_data *us, unsigned long address, · line 954

Quoted 3 lines
drivers/usb/storage/alauda.c +0 -0
  		unsigned int zone = lba / uzonesize; /* integer division */
  		unsigned int lba_offset = lba - (zone * uzonesize);
  		unsigned int pages;

Secondly, alauda_write_lba() has the same issue.
You also need to check in alauda_write_data().

Regards
Oliver

#3 lore raw
Quoted 32 lines · Oliver Neukum

On 23.05.24 09:22, Shichao Lai wrote:

Hi,

Quoted 14 lines

Since uzonesize may be zero, so a judgement for non-zero is nessesary.

---
  drivers/usb/storage/alauda.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/usb/storage/alauda.c +0 -0
index 115f05a6201a..db075a8c03cb 100644

drivers/usb/storage/alauda.c static int alauda_read_data(struct us_data *us, unsigned long address, · line 951

Quoted 5 lines
drivers/usb/storage/alauda.c +2 -0
@@ -947,6 +947,8 @@ static int alauda_read_data(struct us_data *us, unsigned long address,
      sg = NULL;
 
      while (sectors > 0) {
+             if (!uzonesize)
+                     return USB_STOR_TRANSPORT_ERROR;

May I point out that uzonesize does not change in this function? There is no need to retest within the loop.

drivers/usb/storage/alauda.c static int alauda_read_data(struct us_data *us, unsigned long address, · line 954

Quoted 3 lines
drivers/usb/storage/alauda.c +0 -0
              unsigned int zone = lba / uzonesize; /* integer division */
              unsigned int lba_offset = lba - (zone * uzonesize);
              unsigned int pages;
Quoted 5 lines

Secondly, alauda_write_lba() has the same issue.
You also need to check in alauda_write_data().

Regards
Oliver

Thanks for the helpful tip!
I reviewed the code. Your suggestions can actually avoid repeated checks. And there is also such a problem in alauda_write_lba().
I am a beginner at making patches. May I commit a patch again which fixes both issues you mentioned?

#4 lore raw
Quoted 5 lines · shichao lai

Thanks for the helpful tip!
I reviewed the code. Your suggestions can actually avoid repeated checks. And there is also such a problem in alauda_write_lba().
I am a beginner at making patches. May I commit a patch again which fixes both issues you mentioned?

Hi,

yes, you usually are supposed to change the "[PATCH]" in the subject line to "[PATCHv2]" and add a line in the log describing the difference between the first and second version.

HTH
Oliver