diff mbox series

[v6,16/16] usb: gadget: UMS: fix 64-bit division on ARM32

Message ID 20240403-b4-qcom-livetree-v6-16-130f8f50b538@linaro.org
State New
Headers show
Series Qualcomm platform USB support | expand

Commit Message

Caleb Connolly April 3, 2024, 12:07 p.m. UTC
The patch introducing support for dynamic sector sizes changed the types
used in some divisions, resulting in the compiler attempting to use
libgcc helpers (__aeabi_ldivmod). Replace these divisions with calls to
lldiv() to handle this correctly.

Fixes: 74e56e0c5065 ("usb: gadget: UMS: support multiple sector sizes")
Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
Cc: Mattijs Korpershoek <mkorpershoek@baylibre.com>
---
 drivers/usb/gadget/f_mass_storage.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Caleb Connolly April 3, 2024, 12:27 p.m. UTC | #1
argh, forgot to drop this patch again, will do so while applying.

On 03/04/2024 14:07, Caleb Connolly wrote:
> The patch introducing support for dynamic sector sizes changed the types
> used in some divisions, resulting in the compiler attempting to use
> libgcc helpers (__aeabi_ldivmod). Replace these divisions with calls to
> lldiv() to handle this correctly.
> 
> Fixes: 74e56e0c5065 ("usb: gadget: UMS: support multiple sector sizes")
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
> ---
> Cc: Mattijs Korpershoek <mkorpershoek@baylibre.com>
> ---
>   drivers/usb/gadget/f_mass_storage.c | 13 +++++++------
>   1 file changed, 7 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
> index d880928044f4..ef90c7ec7fb5 100644
> --- a/drivers/usb/gadget/f_mass_storage.c
> +++ b/drivers/usb/gadget/f_mass_storage.c
> @@ -239,8 +239,9 @@
>   /* #define VERBOSE_DEBUG */
>   /* #define DUMP_MSGS */
>   
>   #include <config.h>
> +#include <div64.h>
>   #include <hexdump.h>
>   #include <log.h>
>   #include <malloc.h>
>   #include <common.h>
> @@ -768,10 +769,10 @@ static int do_read(struct fsg_common *common)
>   		}
>   
>   		/* Perform the read */
>   		rc = ums[common->lun].read_sector(&ums[common->lun],
> -				      file_offset / curlun->blksize,
> -				      amount / curlun->blksize,
> +				      lldiv(file_offset, curlun->blksize),
> +				      lldiv(amount, curlun->blksize),
>   				      (char __user *)bh->buf);
>   		if (!rc)
>   			return -EIO;
>   
> @@ -942,10 +943,10 @@ static int do_write(struct fsg_common *common)
>   			amount = bh->outreq->actual;
>   
>   			/* Perform the write */
>   			rc = ums[common->lun].write_sector(&ums[common->lun],
> -					       file_offset / curlun->blksize,
> -					       amount / curlun->blksize,
> +					       lldiv(file_offset, curlun->blksize),
> +					       lldiv(amount, curlun->blksize),
>   					       (char __user *)bh->buf);
>   			if (!rc)
>   				return -EIO;
>   			nwritten = rc * curlun->blksize;
> @@ -1058,10 +1059,10 @@ static int do_verify(struct fsg_common *common)
>   		}
>   
>   		/* Perform the read */
>   		rc = ums[common->lun].read_sector(&ums[common->lun],
> -				      file_offset / curlun->blksize,
> -				      amount / curlun->blksize,
> +				      lldiv(file_offset, curlun->blksize),
> +				      lldiv(amount, curlun->blksize),
>   				      (char __user *)bh->buf);
>   		if (!rc)
>   			return -EIO;
>   		nread = rc * curlun->blksize;
>
diff mbox series

Patch

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index d880928044f4..ef90c7ec7fb5 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -239,8 +239,9 @@ 
 /* #define VERBOSE_DEBUG */
 /* #define DUMP_MSGS */
 
 #include <config.h>
+#include <div64.h>
 #include <hexdump.h>
 #include <log.h>
 #include <malloc.h>
 #include <common.h>
@@ -768,10 +769,10 @@  static int do_read(struct fsg_common *common)
 		}
 
 		/* Perform the read */
 		rc = ums[common->lun].read_sector(&ums[common->lun],
-				      file_offset / curlun->blksize,
-				      amount / curlun->blksize,
+				      lldiv(file_offset, curlun->blksize),
+				      lldiv(amount, curlun->blksize),
 				      (char __user *)bh->buf);
 		if (!rc)
 			return -EIO;
 
@@ -942,10 +943,10 @@  static int do_write(struct fsg_common *common)
 			amount = bh->outreq->actual;
 
 			/* Perform the write */
 			rc = ums[common->lun].write_sector(&ums[common->lun],
-					       file_offset / curlun->blksize,
-					       amount / curlun->blksize,
+					       lldiv(file_offset, curlun->blksize),
+					       lldiv(amount, curlun->blksize),
 					       (char __user *)bh->buf);
 			if (!rc)
 				return -EIO;
 			nwritten = rc * curlun->blksize;
@@ -1058,10 +1059,10 @@  static int do_verify(struct fsg_common *common)
 		}
 
 		/* Perform the read */
 		rc = ums[common->lun].read_sector(&ums[common->lun],
-				      file_offset / curlun->blksize,
-				      amount / curlun->blksize,
+				      lldiv(file_offset, curlun->blksize),
+				      lldiv(amount, curlun->blksize),
 				      (char __user *)bh->buf);
 		if (!rc)
 			return -EIO;
 		nread = rc * curlun->blksize;