All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roel Kluin <roel.kluin@gmail.com>
To: Greg Kroah-Hartman <gregkh@suse.de>,
	devel@driverdev.osuosl.org,
	Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] Staging: Cleanup redundant tests on unsigned
Date: Fri, 23 Oct 2009 14:55:57 +0200	[thread overview]
Message-ID: <4AE1A7DD.5000107@gmail.com> (raw)

The variables are unsigned so the test `>= 0' is always true,
the `< 0' test always fails. In these cases the other part of
the test catches wrapped values.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
 drivers/staging/comedi/comedi_fops.c     |    4 +-
 drivers/staging/go7007/go7007-v4l2.c     |    2 +-
 drivers/staging/rt2860/common/cmm_info.c |   37 ++++++++++-------------------
 drivers/staging/rt3090/common/cmm_info.c |    8 +++---
 drivers/staging/usbip/vhci_sysfs.c       |    2 +-
 5 files changed, 21 insertions(+), 32 deletions(-)

diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index aaad76e..8425806 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -300,7 +300,7 @@ static int do_bufconfig_ioctl(struct comedi_device *dev, void *arg)
 	if (copy_from_user(&bc, arg, sizeof(struct comedi_bufconfig)))
 		return -EFAULT;
 
-	if (bc.subdevice >= dev->n_subdevices || bc.subdevice < 0)
+	if (bc.subdevice >= dev->n_subdevices)
 		return -EINVAL;
 
 	s = dev->subdevices + bc.subdevice;
@@ -556,7 +556,7 @@ static int do_bufinfo_ioctl(struct comedi_device *dev, void *arg)
 	if (copy_from_user(&bi, arg, sizeof(struct comedi_bufinfo)))
 		return -EFAULT;
 
-	if (bi.subdevice >= dev->n_subdevices || bi.subdevice < 0)
+	if (bi.subdevice >= dev->n_subdevices)
 		return -EINVAL;
 
 	s = dev->subdevices + bi.subdevice;
diff --git a/drivers/staging/go7007/go7007-v4l2.c b/drivers/staging/go7007/go7007-v4l2.c
index 4bd353a..2e20a6a 100644
--- a/drivers/staging/go7007/go7007-v4l2.c
+++ b/drivers/staging/go7007/go7007-v4l2.c
@@ -809,7 +809,7 @@ static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
 		return retval;
 
 	mutex_lock(&gofh->lock);
-	if (buf->index < 0 || buf->index >= gofh->buf_count)
+	if (buf->index >= gofh->buf_count)
 		goto unlock_and_return;
 
 	gobuf = &gofh->bufs[buf->index];
diff --git a/drivers/staging/rt2860/common/cmm_info.c b/drivers/staging/rt2860/common/cmm_info.c
index 019cc44..7b9f929 100644
--- a/drivers/staging/rt2860/common/cmm_info.c
+++ b/drivers/staging/rt2860/common/cmm_info.c
@@ -249,22 +249,16 @@ INT Set_CountryRegion_Proc(
 	region = simple_strtol(arg, 0, 10);
 
 	// Country can be set only when EEPROM not programmed
-	if (pAd->CommonCfg.CountryRegion & 0x80)
-	{
+	if (pAd->CommonCfg.CountryRegion & 0x80) {
 		DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegion_Proc::parameter of CountryRegion in eeprom is programmed \n"));
 		return FALSE;
 	}
 
-	if((region >= 0) && (region <= REGION_MAXIMUM_BG_BAND))
-	{
+	if (region <= REGION_MAXIMUM_BG_BAND) {
 		pAd->CommonCfg.CountryRegion = (UCHAR) region;
-	}
-	else if (region == REGION_31_BG_BAND)
-	{
+	} else if (region == REGION_31_BG_BAND) {
 		pAd->CommonCfg.CountryRegion = (UCHAR) region;
-	}
-	else
-	{
+	} else {
 		DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegion_Proc::parameters out of range\n"));
 		return FALSE;
 	}
@@ -295,18 +289,14 @@ INT Set_CountryRegionABand_Proc(
 	region = simple_strtol(arg, 0, 10);
 
 	// Country can be set only when EEPROM not programmed
-	if (pAd->CommonCfg.CountryRegionForABand & 0x80)
-	{
+	if (pAd->CommonCfg.CountryRegionForABand & 0x80) {
 		DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegionABand_Proc::parameter of CountryRegion in eeprom is programmed \n"));
 		return FALSE;
 	}
 
-	if((region >= 0) && (region <= REGION_MAXIMUM_A_BAND))
-	{
+	if (region <= REGION_MAXIMUM_A_BAND) {
 		pAd->CommonCfg.CountryRegionForABand = (UCHAR) region;
-	}
-	else
-	{
+	} else {
 		DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegionABand_Proc::parameters out of range\n"));
 		return FALSE;
 	}
@@ -2194,13 +2184,13 @@ INT	Set_HtMcs_Proc(
 			(pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE < MODE_HTMIX))
 		{
 	        if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
-				(HtMcs >= 0 && HtMcs <= 3) &&
+				(HtMcs <= 3) &&
 	            (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_CCK))
 			{
 				RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs] * 1000000));
 			}
 	        else if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
-					(HtMcs >= 0 && HtMcs <= 7) &&
+					(HtMcs <= 7) &&
 	            	(pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_OFDM))
 			{
 				RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs+4] * 1000000));
@@ -2255,10 +2245,9 @@ INT	Set_HtTxBASize_Proc(
 
 	Size = simple_strtol(arg, 0, 10);
 
-	if (Size <=0 || Size >=64)
-	{
+	if (Size == 0 || Size >= 64)
 		Size = 8;
-	}
+
 	pAd->CommonCfg.TxBASize = Size-1;
 	DBGPRINT(RT_DEBUG_ERROR, ("Set_HtTxBASize ::(TxBASize= %d)\n", Size));
 
@@ -2364,7 +2353,7 @@ INT	Set_HtMpduDensity_Proc(
 
 	Value = simple_strtol(arg, 0, 10);
 
-	if (Value <=7 && Value >= 0)
+	if (Value <= 7)
 		pAd->CommonCfg.BACapability.field.MpduDensity = Value;
 	else
 		pAd->CommonCfg.BACapability.field.MpduDensity = 4;
@@ -2582,7 +2571,7 @@ INT	Set_HtMIMOPSmode_Proc(
 
 	Value = simple_strtol(arg, 0, 10);
 
-	if (Value <=3 && Value >= 0)
+	if (Value <= 3)
 		pAd->CommonCfg.BACapability.field.MMPSmode = Value;
 	else
 		pAd->CommonCfg.BACapability.field.MMPSmode = 3;
diff --git a/drivers/staging/rt3090/common/cmm_info.c b/drivers/staging/rt3090/common/cmm_info.c
index 3e51e98..c710f85 100644
--- a/drivers/staging/rt3090/common/cmm_info.c
+++ b/drivers/staging/rt3090/common/cmm_info.c
@@ -2548,13 +2548,13 @@ INT	Set_HtMcs_Proc(
 			(pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE < MODE_HTMIX))
 		{
 	        if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
-				(HtMcs >= 0 && HtMcs <= 3) &&
+				(HtMcs <= 3) &&
 	            (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_CCK))
 			{
 				RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs] * 1000000));
 			}
 	        else if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
-					(HtMcs >= 0 && HtMcs <= 7) &&
+					(HtMcs <= 7) &&
 			(pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_OFDM))
 			{
 				RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs+4] * 1000000));
@@ -2741,7 +2741,7 @@ INT	Set_HtMpduDensity_Proc(
 
 	Value = simple_strtol(arg, 0, 10);
 
-	if (Value <=7 && Value >= 0)
+	if (Value <= 7)
 		pAd->CommonCfg.BACapability.field.MpduDensity = Value;
 	else
 		pAd->CommonCfg.BACapability.field.MpduDensity = 4;
@@ -2959,7 +2959,7 @@ INT	Set_HtMIMOPSmode_Proc(
 
 	Value = simple_strtol(arg, 0, 10);
 
-	if (Value <=3 && Value >= 0)
+	if (Value <= 3)
 		pAd->CommonCfg.BACapability.field.MMPSmode = Value;
 	else
 		pAd->CommonCfg.BACapability.field.MMPSmode = 3;
diff --git a/drivers/staging/usbip/vhci_sysfs.c b/drivers/staging/usbip/vhci_sysfs.c
index d8992d1..260be8a 100644
--- a/drivers/staging/usbip/vhci_sysfs.c
+++ b/drivers/staging/usbip/vhci_sysfs.c
@@ -134,7 +134,7 @@ static DEVICE_ATTR(detach, S_IWUSR, NULL, store_detach);
 static int valid_args(__u32 rhport, enum usb_device_speed speed)
 {
 	/* check rhport */
-	if ((rhport < 0) || (rhport >= VHCI_NPORTS)) {
+	if (rhport >= VHCI_NPORTS) {
 		usbip_uerr("port %u\n", rhport);
 		return -EINVAL;
 	}

                 reply	other threads:[~2009-10-23 12:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AE1A7DD.5000107@gmail.com \
    --to=roel.kluin@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.