public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] usb-storage: Check whether divisor is non-zero before division
@ 2024-05-23 11:34 Shichao Lai
  2024-05-23 11:47 ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Shichao Lai @ 2024-05-23 11:34 UTC (permalink / raw)
  To: stern, gregkh, oneukum
  Cc: linux-usb, usb-storage, linux-kernel, Shichao Lai, xingwei lee,
	yue sun

Since uzonesize may be zero, so judgements for non-zero
are nessesary in both place.

Changes since v1:
- Add one more check in alauda_write_lba().
- Move check ahead of loop in alauda_read_data().

Reported-by: xingwei lee <xrivendell7@gmail.com>
Reported-by: yue sun <samsun1006219@gmail.com>
Signed-off-by: Shichao Lai <shichaorai@gmail.com>
---
 drivers/usb/storage/alauda.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c
index 115f05a6201a..17c73acd3b02 100644
--- a/drivers/usb/storage/alauda.c
+++ b/drivers/usb/storage/alauda.c
@@ -813,6 +813,8 @@ static int alauda_write_lba(struct us_data *us, u16 lba,
 	unsigned char ecc[3];
 	int i, result;
 	unsigned int uzonesize = MEDIA_INFO(us).uzonesize;
+	if (!uzonesize)
+		return USB_STOR_TRANSPORT_ERROR;
 	unsigned int zonesize = MEDIA_INFO(us).zonesize;
 	unsigned int pagesize = MEDIA_INFO(us).pagesize;
 	unsigned int blocksize = MEDIA_INFO(us).blocksize;
@@ -921,6 +923,8 @@ static int alauda_read_data(struct us_data *us, unsigned long address,
 	unsigned int blocksize = MEDIA_INFO(us).blocksize;
 	unsigned int pagesize = MEDIA_INFO(us).pagesize;
 	unsigned int uzonesize = MEDIA_INFO(us).uzonesize;
+	if (!uzonesize)
+		return USB_STOR_TRANSPORT_ERROR;
 	struct scatterlist *sg;
 	int result;
 
-- 
2.34.1


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

end of thread, other threads:[~2024-05-23 12:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-23 11:34 [PATCH v2] usb-storage: Check whether divisor is non-zero before division Shichao Lai
2024-05-23 11:47 ` Greg KH
2024-05-23 12:23   ` shichao lai
2024-05-23 12:37     ` Greg KH

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