Skip to contentSkip to conversation

iio: frequency: adf4350: using an uninitialized variable

PATCH In review Dan Carpenter 2 participants 2 messages Jun 8, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 iio: frequency: adf4350: using an uninitialized variable

GCC complains that we use an uninitialized variable if the user passes an invalid parameter to adf4350_read(). I decided that we should return -EINVAL instead in that case.

However, when I looked up at adf4350_write() it returned -ENODEV for that condition. In the end, I decided the -EINVAL was the right thing and I change adf4350_write() to match.

drivers/iio/frequency/adf4350.c +3 -1
index fd4c850..4729bba 100644
@@ -272,7 +272,7 @@ static ssize_t adf4350_write(struct iio_dev *indio_dev,
 		adf4350_sync_config(st);
 		break;
 	default:
-		ret = -ENODEV;
+		ret = -EINVAL;
 	}
 	mutex_unlock(&indio_dev->mlock);
 
@@ -310,6 +310,8 @@ static ssize_t adf4350_read(struct iio_dev *indio_dev,
 	case ADF4350_PWRDOWN:
 		val = !!(st->regs[ADF4350_REG2] & ADF4350_REG2_POWER_DOWN_EN);
 		break;
+	default:
+		ret = -EINVAL;
 	}
 	mutex_unlock(&indio_dev->mlock);
 
maintainer Acked-by on v1 1/2
#1 lore raw
Quoted 7 lines · Dan Carpenter

GCC complains that we use an uninitialized variable if the user passes an invalid parameter to adf4350_read(). I decided that we should return -EINVAL instead in that case.

However, when I looked up at adf4350_write() it returned -ENODEV for that condition. In the end, I decided the -EINVAL was the right thing and I change adf4350_write() to match.

Agreed.

Quoted 2 lines
Quoted 24 lines
drivers/iio/frequency/adf4350.c +3 -1
index fd4c850..4729bba 100644
@@ -272,7 +272,7 @@ static ssize_t adf4350_write(struct iio_dev *indio_dev,
  		adf4350_sync_config(st);
  		break;
  	default:
-		ret = -ENODEV;
+		ret = -EINVAL;
  	}
  	mutex_unlock(&indio_dev->mlock);
 
@@ -310,6 +310,8 @@ static ssize_t adf4350_read(struct iio_dev *indio_dev,
  	case ADF4350_PWRDOWN:
  		val = !!(st->regs[ADF4350_REG2]&  ADF4350_REG2_POWER_DOWN_EN);
  		break;
+	default:
+		ret = -EINVAL;
  	}
  	mutex_unlock(&indio_dev->mlock);
 
Signature · 8 lines
Greetings,
Michael

--
Analog Devices GmbH      Wilhelm-Wagenfeld-Str. 6      80807 Muenchen
Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368;
Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin,
Margaret Seif