Re: [PATCH] gadget/mass_storage: remove >= 0 check for unsigned type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Dec 03 2012, Sebastian Andrzej Siewior wrote:
> | In file included from drivers/usb/gadget/acm_ms.c:43:
> | f_mass_storage.c:2199:18: warning: comparison of unsigned expression >= 0 is always true  [-Wtautological-compare]
> |         if (common->lun >= 0 && common->lun < common->nluns)
> |             ~~~~~~~~~~~ ^  ~
>
> common->lun is defined as "unsigned int" so its value is always >= 0.
> It is assigned via cbw->Lun which is defined as u8 so it is also not
> abused as -1.
>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>

Acked-by: Michal Nazarewicz <mina86@xxxxxxxxxx>

While at it, could you also squash the following into your patch:

diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
index 5d027b3..fe46e72 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -1718,7 +1718,7 @@ static int check_command(struct fsg_common *common, int cmnd_size,
                         int needs_medium, const char *name)
 {
        int                     i;
-       int                     lun = common->cmnd[1] >> 5;
+       unsigned int            lun = common->cmnd[1] >> 5;
        static const char       dirletter[4] = {'u', 'o', 'i', 'n'};
        char                    hdlen[20];
        struct fsg_lun          *curlun;
@@ -1784,7 +1784,7 @@ static int check_command(struct fsg_common *common, int cmnd_size,
 
        /* Check that the LUN values are consistent */
        if (common->lun != lun)
-               DBG(common, "using LUN %d from CBW, not LUN %d from CDB\n",
+               DBG(common, "using LUN %u from CBW, not LUN %u from CDB\n",
                    common->lun, lun);
 
        /* Check the LUN */
@@ -1804,7 +1804,7 @@ static int check_command(struct fsg_common *common, int cmnd_size,
                 */
                if (common->cmnd[0] != INQUIRY &&
                    common->cmnd[0] != REQUEST_SENSE) {
-                       DBG(common, "unsupported LUN %d\n", common->lun);
+                       DBG(common, "unsupported LUN %u\n", common->lun);
                        return -EINVAL;
                }
        }

> ---
>  drivers/usb/gadget/f_mass_storage.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/gadget/f_mass_storage.c b/drivers/usb/gadget/f_mass_storage.c
> index 5d027b3..a87c1a1 100644
> --- a/drivers/usb/gadget/f_mass_storage.c
> +++ b/drivers/usb/gadget/f_mass_storage.c
> @@ -2196,7 +2196,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
>  	if (common->data_size == 0)
>  		common->data_dir = DATA_DIR_NONE;
>  	common->lun = cbw->Lun;
> -	if (common->lun >= 0 && common->lun < common->nluns)
> +	if (common->lun < common->nluns)
>  		common->curlun = &common->luns[common->lun];
>  	else
>  		common->curlun = NULL;

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +----<email/xmpp: mpn@xxxxxxxxxx>--------------ooO--(_)--Ooo--

Attachment: pgpG1dgBXe02H.pgp
Description: PGP signature


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux