Skip to contentSkip to conversation

staging: iio: Remove explicit comparisons

PATCH Superseded Cristina Moraru 2 participants 24 messages Oct 19, 2015 – Oct 20, 2015

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

cover staging: iio: Remove explicit comparisons

Remove comparisons to 0 or NULL in order to provide efficiency. Done with coccinelle
@replace@
identifier e;
@@
(
-e == 0
+ !e
|
-e != 0
+ e
|
-e == NULL
+ !e
|
-e != NULL
+ e
)

Cristina Moraru (10):
staging: iio: adc: Remove explicit comparisons
staging: iio: addac: Remove explicit comparisons
staging: iio: light: Remove explicit comparisons
staging: iio: meter: Remove explicit comparisons
staging: iio: accel: Remove explicit comparisons
staging: iio: cdc: Remove explicit comparisons
staging: iio: frequency: Remove explicit comparisons
staging: iio: trigger: Remove explicit comparisons
staging: iio: gyro: Remove explicit comparisons
staging: iio: magnetometer: Remove explicit comparisons

 drivers/staging/iio/accel/sca3000_ring.c            |  2 +-
 drivers/staging/iio/adc/ad7192.c                    |  4 ++--
 drivers/staging/iio/adc/ad7280a.c                   |  6 +++---
 drivers/staging/iio/adc/mxs-lradc.c                 | 10 +++++-----
 drivers/staging/iio/adc/spear_adc.c                 |  2 +-
 drivers/staging/iio/addac/adt7316.c                 |  4 ++--
 drivers/staging/iio/cdc/ad7150.c                    |  2 +-
 drivers/staging/iio/cdc/ad7152.c                    |  2 +-
 drivers/staging/iio/frequency/ad9832.c              |  2 +-
 drivers/staging/iio/frequency/ad9834.c              |  2 +-
 drivers/staging/iio/gyro/adis16060_core.c           |  2 +-
 drivers/staging/iio/light/isl29018.c                |  6 +++---
 drivers/staging/iio/light/tsl2583.c                 |  6 +++---
 drivers/staging/iio/light/tsl2x7x_core.c            |  6 +++---
 drivers/staging/iio/magnetometer/hmc5843_core.c     |  2 +-
 drivers/staging/iio/meter/ade7753.c                 |  2 +-
 drivers/staging/iio/meter/ade7754.c                 |  2 +-
 drivers/staging/iio/meter/ade7759.c                 |  2 +-
 drivers/staging/iio/meter/ade7854-spi.c             |  2 +-
 drivers/staging/iio/trigger/iio-trig-bfin-timer.c   |  4 ++--
 drivers/staging/iio/trigger/iio-trig-periodic-rtc.c |  4 ++--
 21 files changed, 37 insertions(+), 37 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/10 staging: iio: adc: Remove explicit comparisons

Remove comparisons to 0 or NULL in order to provide efficiency

---
 drivers/staging/iio/adc/ad7192.c    |  4 ++--
 drivers/staging/iio/adc/ad7280a.c   |  6 +++---
 drivers/staging/iio/adc/mxs-lradc.c | 10 +++++-----
 drivers/staging/iio/adc/spear_adc.c |  2 +-
 4 files changed, 11 insertions(+), 11 deletions(-)
drivers/staging/iio/adc/ad7192.c +2 -2
index fe56fb6..beb31d3 100644
@@ -330,7 +330,7 @@ static ssize_t ad7192_write_frequency(struct device *dev,
 	ret = kstrtoul(buf, 10, &lval);
 	if (ret)
 		return ret;
-	if (lval == 0)
+	if (!lval)
 		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
@@ -625,7 +625,7 @@ static int ad7192_probe(struct spi_device *spi)
 	}
 
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
-	if (indio_dev == NULL)
+	if (!indio_dev)
 		return -ENOMEM;
 
 	st = iio_priv(indio_dev);
drivers/staging/iio/adc/ad7280a.c +3 -3
index edbfba1..5c731b6 100644
@@ -365,7 +365,7 @@ static int ad7280_chain_setup(struct ad7280_state *st)
 
 	for (n = 0; n <= AD7280A_MAX_CHAIN; n++) {
 		__ad7280_read32(st, &val);
-		if (val == 0)
+		if (!val)
 			return n - 1;
 
 		if (ad7280_check_crc(st, val))
@@ -686,7 +686,7 @@ static irqreturn_t ad7280_event_handler(int irq, void *private)
 	int i, ret;
 
 	channels = kcalloc(st->scan_cnt, sizeof(*channels), GFP_KERNEL);
-	if (channels == NULL)
+	if (!channels)
 		return IRQ_HANDLED;
 
 	ret = ad7280_read_all_channels(st, st->scan_cnt, channels);
@@ -839,7 +839,7 @@ static int ad7280_probe(struct spi_device *spi)
 	struct iio_dev *indio_dev;
 
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
-	if (indio_dev == NULL)
+	if (!indio_dev)
 		return -ENOMEM;
 
 	st = iio_priv(indio_dev);
drivers/staging/iio/adc/mxs-lradc.c +5 -5
index 3f7715c..88bd084 100644
@@ -566,7 +566,7 @@ static unsigned mxs_lradc_read_ts_pressure(struct mxs_lradc *lradc,
 	m1 = mxs_lradc_read_raw_channel(lradc, ch1);
 	m2 = mxs_lradc_read_raw_channel(lradc, ch2);
 
-	if (m2 == 0) {
+	if (!m2) {
 		dev_warn(lradc->dev, "Cannot calculate pressure\n");
 		return 1 << (LRADC_RESOLUTION - 1);
 	}
@@ -1217,7 +1217,7 @@ static int mxs_lradc_trigger_init(struct iio_dev *iio)
 	struct mxs_lradc *lradc = iio_priv(iio);
 
 	trig = iio_trigger_alloc("%s-dev%i", iio->name, iio->id);
-	if (trig == NULL)
+	if (!trig)
 		return -ENOMEM;
 
 	trig->dev.parent = lradc->dev;
@@ -1608,14 +1608,14 @@ static int mxs_lradc_probe(struct platform_device *pdev)
 		return PTR_ERR(lradc->clk);
 	}
 	ret = clk_prepare_enable(lradc->clk);
-	if (ret != 0) {
+	if (ret) {
 		dev_err(dev, "Failed to enable the delay unit clock\n");
 		return ret;
 	}
 
 	touch_ret = mxs_lradc_probe_touchscreen(lradc, node);
 
-	if (touch_ret == 0)
+	if (!touch_ret)
 		lradc->buffer_vchans = BUFFER_VCHANS_LIMITED;
 	else
 		lradc->buffer_vchans = BUFFER_VCHANS_ALL;
@@ -1692,7 +1692,7 @@ static int mxs_lradc_probe(struct platform_device *pdev)
 		goto err_dev;
 
 	/* Register the touchscreen input device. */
-	if (touch_ret == 0) {
+	if (!touch_ret) {
 		ret = mxs_lradc_ts_register(lradc);
 		if (ret)
 			goto err_ts_register;
drivers/staging/iio/adc/spear_adc.c +1 -1
index c538237..d721242 100644
@@ -192,7 +192,7 @@ static int spear_adc_write_raw(struct iio_dev *indio_dev,
 
 	if ((val < SPEAR_ADC_CLK_MIN) ||
 		(val > SPEAR_ADC_CLK_MAX) ||
-		(val2 != 0)) {
+		val2) {
 		ret = -EINVAL;
 		goto out;
 	}
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/10 staging: iio: addac: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL in order to provide efficiency

---
 drivers/staging/iio/addac/adt7316.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/addac/adt7316.c +2 -2
index 3adc451..cb23fec 100644
@@ -1419,7 +1419,7 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip,
 	int ret;
 
 	if (channel >= ADT7316_DA_MSB_DATA_REGS ||
-		(channel == 0 &&
+		(!channel &&
 		(chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) ||
 		(channel == 1 &&
 		(chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB)))
@@ -1452,7 +1452,7 @@ static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip,
 	int ret;
 
 	if (channel >= ADT7316_DA_MSB_DATA_REGS ||
-		(channel == 0 &&
+		(!channel &&
 		(chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) ||
 		(channel == 1 &&
 		(chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB)))
Signature · 1 line
1.9.1
#3 lore raw

Re: [Outreachy kernel] [PATCH 02/10] staging: iio: addac: Remove explicit comparisons

drivers/staging/iio/addac/adt7316.c static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip, · line 1422

Quoted 10 lines
drivers/staging/iio/addac/adt7316.c +1 -1
index 3adc451..cb23fec 100644
@@ -1419,7 +1419,7 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip,
 	int ret;
 
 	if (channel >= ADT7316_DA_MSB_DATA_REGS ||
-		(channel == 0 &&
+		(!channel &&

Here too it is probably better to keep the comparison to 0, since there is a comparison to 1 just below. Same in the next case.

julia

Quoted 22 lines
drivers/staging/iio/addac/adt7316.c +1 -1
 		(chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) ||
 		(channel == 1 &&
 		(chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB)))
@@ -1452,7 +1452,7 @@ static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip,
 	int ret;
 
 	if (channel >= ADT7316_DA_MSB_DATA_REGS ||
-		(channel == 0 &&
+		(!channel &&
 		(chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) ||
 		(channel == 1 &&
 		(chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB)))
Signature · 8 lines
1.9.1

-- 
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/933f0eb8aa4bb81e75671c9531bf4d59d78e3ceb.1445291799.git.cristina.moraru09%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
#4 lore raw

PATCH 3/10 staging: iio: light: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL in order to provide efficiency

---
 drivers/staging/iio/light/isl29018.c     | 6 +++---
 drivers/staging/iio/light/tsl2583.c      | 6 +++---
 drivers/staging/iio/light/tsl2x7x_core.c | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
drivers/staging/iio/light/isl29018.c +3 -3
index 019ba52..5be3dd2 100644
@@ -335,7 +335,7 @@ static ssize_t store_prox_infrared_suppression(struct device *dev,
 
 	if (kstrtoint(buf, 10, &val))
 		return -EINVAL;
-	if (!(val == 0 || val == 1)) {
+	if (!(!val || val == 1)) {
 		dev_err(dev, "The mode is not supported\n");
 		return -EINVAL;
 	}
@@ -370,7 +370,7 @@ static int isl29018_write_raw(struct iio_dev *indio_dev,
 		break;
 	case IIO_CHAN_INFO_INT_TIME:
 		if (chan->type == IIO_LIGHT) {
-			if (val != 0) {
+			if (val) {
 				mutex_unlock(&chip->lock);
 				return -EINVAL;
 			}
@@ -716,7 +716,7 @@ static int isl29018_probe(struct i2c_client *client,
 	int dev_id = 0;
 
 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip));
-	if (indio_dev == NULL) {
+	if (!indio_dev) {
 		dev_err(&client->dev, "iio allocation fails\n");
 		return -ENOMEM;
 	}
drivers/staging/iio/light/tsl2583.c +3 -3
index df60203..3100d96 100644
@@ -263,7 +263,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
 	if ((ch0 >= chip->als_saturation) || (ch1 >= chip->als_saturation))
 		goto return_max;
 
-	if (ch0 == 0) {
+	if (!ch0) {
 		/* have no data, so return LAST VALUE */
 		ret = chip->als_cur_info.lux = 0;
 		goto out_unlock;
@@ -415,7 +415,7 @@ static int taos_chip_on(struct iio_dev *indio_dev)
 
 	/* determine als integration register */
 	als_count = (chip->taos_settings.als_time * 100 + 135) / 270;
-	if (als_count == 0)
+	if (!als_count)
 		als_count = 1; /* ensure at least one cycle */
 
 	/* convert back to time (encompasses overrides) */
@@ -499,7 +499,7 @@ static ssize_t taos_power_state_store(struct device *dev,
 	if (kstrtoint(buf, 0, &value))
 		return -EINVAL;
 
-	if (value == 0)
+	if (!value)
 		taos_chip_off(indio_dev);
 	else
 		taos_chip_on(indio_dev);
drivers/staging/iio/light/tsl2x7x_core.c +3 -3
index 010e607..c43bab9 100644
@@ -403,7 +403,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
 		goto return_max;
 	}
 
-	if (ch0 == 0) {
+	if (!ch0) {
 		/* have no data, so return LAST VALUE */
 		ret = chip->als_cur_info.lux;
 		goto out_unlock;
@@ -678,7 +678,7 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 
 	/* determine als integration register */
 	als_count = (chip->tsl2x7x_settings.als_time * 100 + 135) / 270;
-	if (als_count == 0)
+	if (!als_count)
 		als_count = 1; /* ensure at least one cycle */
 
 	/* convert back to time (encompasses overrides) */
@@ -825,7 +825,7 @@ void tsl2x7x_prox_calculate(int *data, int length,
 	int sample_sum;
 	int tmp;
 
-	if (length == 0)
+	if (!length)
 		length = 1;
 
 	sample_sum = 0;
Signature · 1 line
1.9.1
#5 lore raw

Re: [Outreachy kernel] [PATCH 03/10] staging: iio: light: Remove explicit comparisons

drivers/staging/iio/light/isl29018.c static ssize_t store_prox_infrared_suppression(struct device *dev, · line 338

Quoted 4 lines
drivers/staging/iio/light/isl29018.c +1 -1
 	if (kstrtoint(buf, 10, &val))
 		return -EINVAL;
-	if (!(val == 0 || val == 1)) {
+	if (!(!val || val == 1)) {

This one looked nicer with the comparison to 0, since that is more parallel with the comparison to 1.

julia

#6 lore raw

PATCH 4/10 staging: iio: meter: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL in order to provide efficiency

---
 drivers/staging/iio/meter/ade7753.c     | 2 +-
 drivers/staging/iio/meter/ade7754.c     | 2 +-
 drivers/staging/iio/meter/ade7759.c     | 2 +-
 drivers/staging/iio/meter/ade7854-spi.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
drivers/staging/iio/meter/ade7753.c +1 -1
index 3d2e50c..188830d 100644
@@ -406,7 +406,7 @@ static ssize_t ade7753_write_frequency(struct device *dev,
 	ret = kstrtou16(buf, 10, &val);
 	if (ret)
 		return ret;
-	if (val == 0)
+	if (!val)
 		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
drivers/staging/iio/meter/ade7754.c +1 -1
index 8552c76..664c6e5 100644
@@ -438,7 +438,7 @@ static ssize_t ade7754_write_frequency(struct device *dev,
 	ret = kstrtou16(buf, 10, &val);
 	if (ret)
 		return ret;
-	if (val == 0)
+	if (!val)
 		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
drivers/staging/iio/meter/ade7759.c +1 -1
index 23e7392..11c1edc 100644
@@ -377,7 +377,7 @@ static ssize_t ade7759_write_frequency(struct device *dev,
 	ret = kstrtou16(buf, 10, &val);
 	if (ret)
 		return ret;
-	if (val == 0)
+	if (!val)
 		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
drivers/staging/iio/meter/ade7854-spi.c +1 -1
index 9b255a5..da77486 100644
@@ -278,7 +278,7 @@ static int ade7854_spi_probe(struct spi_device *spi)
 	struct iio_dev *indio_dev;
 
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
-	if (indio_dev == NULL)
+	if (!indio_dev)
 		return -ENOMEM;
 	st = iio_priv(indio_dev);
 	spi_set_drvdata(spi, indio_dev);
Signature · 1 line
1.9.1
#7 lore raw

PATCH 5/10 staging: iio: accel: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL in order to provide efficiency

---
 drivers/staging/iio/accel/sca3000_ring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/accel/sca3000_ring.c +1 -1
index 23685e7..6d19e12 100644
@@ -267,7 +267,7 @@ int sca3000_configure_ring(struct iio_dev *indio_dev)
 	struct iio_buffer *buffer;
 
 	buffer = sca3000_rb_allocate(indio_dev);
-	if (buffer == NULL)
+	if (!buffer)
 		return -ENOMEM;
 	indio_dev->modes |= INDIO_BUFFER_HARDWARE;
 
Signature · 1 line
1.9.1
#8 lore raw

PATCH 6/10 staging: iio: cdc: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL in order to provide efficiency

---
 drivers/staging/iio/cdc/ad7150.c | 2 +-
 drivers/staging/iio/cdc/ad7152.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/cdc/ad7150.c +1 -1
index ff83394..9ba8f46 100644
@@ -222,7 +222,7 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev,
 	u64 event_code;
 
 	/* Something must always be turned on */
-	if (state == 0)
+	if (!state)
 		return -EINVAL;
 
 	event_code = IIO_UNMOD_EVENT_CODE(chan->type, chan->channel, type, dir);
drivers/staging/iio/cdc/ad7152.c +1 -1
index c3d5531..485d0a5 100644
@@ -290,7 +290,7 @@ static int ad7152_write_raw(struct iio_dev *indio_dev,
 		ret = 0;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-		if (val != 0) {
+		if (val) {
 			ret = -EINVAL;
 			goto out;
 		}
Signature · 1 line
1.9.1
#9 lore raw

PATCH 7/10 staging: iio: frequency: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL in order to provide efficiency

---
 drivers/staging/iio/frequency/ad9832.c | 2 +-
 drivers/staging/iio/frequency/ad9834.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/frequency/ad9832.c +1 -1
index a861fe0..b9992bf 100644
@@ -109,7 +109,7 @@ static ssize_t ad9832_write(struct device *dev, struct device_attribute *attr,
 	case AD9832_FREQ_SYM:
 		if (val == 1) {
 			st->ctrl_fp |= AD9832_FREQ;
-		} else if (val == 0) {
+		} else if (!val) {
 			st->ctrl_fp &= ~AD9832_FREQ;
 		} else {
 			ret = -EINVAL;
drivers/staging/iio/frequency/ad9834.c +1 -1
index d02bb44..fcffe2c 100644
@@ -111,7 +111,7 @@ static ssize_t ad9834_write(struct device *dev,
 		break;
 	case AD9834_FSEL:
 	case AD9834_PSEL:
-		if (val == 0) {
+		if (!val) {
 			st->control &= ~(this_attr->address | AD9834_PIN_SW);
 		} else if (val == 1) {
 			st->control |= this_attr->address;
Signature · 1 line
1.9.1
#10 lore raw

PATCH 8/10 staging: iio: trigger: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL in order to provide efficiency

---
 drivers/staging/iio/trigger/iio-trig-bfin-timer.c   | 4 ++--
 drivers/staging/iio/trigger/iio-trig-periodic-rtc.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/staging/iio/trigger/iio-trig-bfin-timer.c +2 -2
index 9fe48ef..035dd45 100644
@@ -100,7 +100,7 @@ static ssize_t iio_bfin_tmr_frequency_store(struct device *dev,
 	if (enabled)
 		disable_gptimers(st->t->bit);
 
-	if (val == 0)
+	if (!val)
 		return count;
 
 	val = get_sclk() / val;
@@ -125,7 +125,7 @@ static ssize_t iio_bfin_tmr_frequency_show(struct device *dev,
 	unsigned int period = get_gptimer_period(st->t->id);
 	unsigned long val;
 
-	if (period == 0)
+	if (!period)
 		val = 0;
 	else
 		val = get_sclk() / get_gptimer_period(st->t->id);
drivers/staging/iio/trigger/iio-trig-periodic-rtc.c +2 -2
index 2db8857..ddce5e2 100644
@@ -39,7 +39,7 @@ static int iio_trig_periodic_rtc_set_state(struct iio_trigger *trig, bool state)
 	dev_dbg(&trig_info->rtc->dev, "trigger frequency is %u\n",
 		trig_info->frequency);
 	ret = rtc_irq_set_state(trig_info->rtc, &trig_info->task, state);
-	if (ret == 0)
+	if (!ret)
 		trig_info->state = state;
 
 	return ret;
@@ -71,7 +71,7 @@ static ssize_t iio_trig_periodic_write_freq(struct device *dev,
 
 	if (val > 0) {
 		ret = rtc_irq_set_freq(trig_info->rtc, &trig_info->task, val);
-		if (ret == 0 && trig_info->state && trig_info->frequency == 0)
+		if (!ret && trig_info->state && trig_info->frequency == 0)
 			ret = rtc_irq_set_state(trig_info->rtc,
 						&trig_info->task, 1);
 	} else {
Signature · 1 line
1.9.1
#11 lore raw

PATCH 9/10 staging: iio: gyro: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL in order to provide efficiency

---
 drivers/staging/iio/gyro/adis16060_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/gyro/adis16060_core.c +1 -1
index 4c5869d..80783e7 100644
@@ -67,7 +67,7 @@ static int adis16060_spi_read(struct iio_dev *indio_dev, u16 *val)
 	 * starts to place data MSB first on the DOUT line at
 	 * the 6th falling edge of SCLK
 	 */
-	if (ret == 0)
+	if (!ret)
 		*val = ((st->buf[0] & 0x3) << 12) |
 			(st->buf[1] << 4) |
 			((st->buf[2] >> 4) & 0xF);
Signature · 1 line
1.9.1
#12 lore raw

PATCH 10/10 staging: iio: magnetometer: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL in order to provide efficiency

---
 drivers/staging/iio/magnetometer/hmc5843_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/magnetometer/hmc5843_core.c +1 -1
index 4aab022..394bc14 100644
@@ -334,7 +334,7 @@ static int hmc5843_get_scale_index(struct hmc5843_data *data, int val, int val2)
 {
 	int i;
 
-	if (val != 0)
+	if (val)
 		return -EINVAL;
 
 	for (i = 0; i < data->variant->n_regval_to_nanoscale; i++)
Signature · 1 line
1.9.1
#13 lore raw

Re: [Outreachy kernel] [PATCH 10/10] staging: iio: magnetometer: Remove explicit comparisons

Quoted 1 line · Cristina Moraru

Remove comparisons to 0 or NULL in order to provide efficiency

I don't think it actually has any impact on effcieincy. The compiler will probably generate the same code in either case. One may think that one looks nicer than the other.

julia

Quoted 29 lines
---
 drivers/staging/iio/magnetometer/hmc5843_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/magnetometer/hmc5843_core.c +1 -1
index 4aab022..394bc14 100644
@@ -334,7 +334,7 @@ static int hmc5843_get_scale_index(struct hmc5843_data *data, int val, int val2)
 {
 	int i;
 
-	if (val != 0)
+	if (val)
 		return -EINVAL;
 
 	for (i = 0; i < data->variant->n_regval_to_nanoscale; i++)
Signature · 8 lines
1.9.1

-- 
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/9d1f4e46279b951b8dff1763ef89b92c14398a3c.1445291799.git.cristina.moraru09%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
#14 lore raw

v2 cover staging: iio: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 and NULL. Done with coccinelle:
@replace@
identifier e;
@@
(
-e == 0
+ !e
|
-e != 0
+ e
|
-e == NULL
+ !e
|
-e != NULL
+ e
)

Changes in v2:
Remove some changes for consistency of notations

Cristina Moraru (9):
staging: iio: adc: Remove explicit comparisons
staging: iio: light: Remove explicit comparisons
staging: iio: meter: Remove explicit comparisons
staging: iio: accel: Remove explicit comparisons
staging: iio: cdc: Remove explicit comparisons
staging: iio: frequency: Remove explicit comparisons
staging: iio: trigger: Remove explicit comparisons
staging: iio: gyro: Remove explicit comparisons
staging: iio: magnetometer: Remove explicit comparisons

 drivers/staging/iio/accel/sca3000_ring.c            |  2 +-
 drivers/staging/iio/adc/ad7192.c                    |  4 ++--
 drivers/staging/iio/adc/ad7280a.c                   |  6 +++---
 drivers/staging/iio/adc/mxs-lradc.c                 | 10 +++++-----
 drivers/staging/iio/adc/spear_adc.c                 |  2 +-
 drivers/staging/iio/cdc/ad7150.c                    |  2 +-
 drivers/staging/iio/cdc/ad7152.c                    |  2 +-
 drivers/staging/iio/frequency/ad9834.c              |  2 +-
 drivers/staging/iio/gyro/adis16060_core.c           |  2 +-
 drivers/staging/iio/light/isl29018.c                |  4 ++--
 drivers/staging/iio/light/tsl2583.c                 |  6 +++---
 drivers/staging/iio/light/tsl2x7x_core.c            |  6 +++---
 drivers/staging/iio/magnetometer/hmc5843_core.c     |  2 +-
 drivers/staging/iio/meter/ade7753.c                 |  2 +-
 drivers/staging/iio/meter/ade7754.c                 |  2 +-
 drivers/staging/iio/meter/ade7759.c                 |  2 +-
 drivers/staging/iio/meter/ade7854-spi.c             |  2 +-
 drivers/staging/iio/trigger/iio-trig-bfin-timer.c   |  4 ++--
 drivers/staging/iio/trigger/iio-trig-periodic-rtc.c |  2 +-
 19 files changed, 32 insertions(+), 32 deletions(-)
Signature · 1 line
1.9.1
#15 lore raw

PATCH v2 1/9 staging: iio: adc: Remove explicit comparisons

Remove comparisons to 0 or NULL

---
 drivers/staging/iio/adc/ad7192.c    |  4 ++--
 drivers/staging/iio/adc/ad7280a.c   |  6 +++---
 drivers/staging/iio/adc/mxs-lradc.c | 10 +++++-----
 drivers/staging/iio/adc/spear_adc.c |  2 +-
 4 files changed, 11 insertions(+), 11 deletions(-)
drivers/staging/iio/adc/ad7192.c +2 -2
index fe56fb6..beb31d3 100644
@@ -330,7 +330,7 @@ static ssize_t ad7192_write_frequency(struct device *dev,
 	ret = kstrtoul(buf, 10, &lval);
 	if (ret)
 		return ret;
-	if (lval == 0)
+	if (!lval)
 		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
@@ -625,7 +625,7 @@ static int ad7192_probe(struct spi_device *spi)
 	}
 
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
-	if (indio_dev == NULL)
+	if (!indio_dev)
 		return -ENOMEM;
 
 	st = iio_priv(indio_dev);
drivers/staging/iio/adc/ad7280a.c +3 -3
index edbfba1..5c731b6 100644
@@ -365,7 +365,7 @@ static int ad7280_chain_setup(struct ad7280_state *st)
 
 	for (n = 0; n <= AD7280A_MAX_CHAIN; n++) {
 		__ad7280_read32(st, &val);
-		if (val == 0)
+		if (!val)
 			return n - 1;
 
 		if (ad7280_check_crc(st, val))
@@ -686,7 +686,7 @@ static irqreturn_t ad7280_event_handler(int irq, void *private)
 	int i, ret;
 
 	channels = kcalloc(st->scan_cnt, sizeof(*channels), GFP_KERNEL);
-	if (channels == NULL)
+	if (!channels)
 		return IRQ_HANDLED;
 
 	ret = ad7280_read_all_channels(st, st->scan_cnt, channels);
@@ -839,7 +839,7 @@ static int ad7280_probe(struct spi_device *spi)
 	struct iio_dev *indio_dev;
 
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
-	if (indio_dev == NULL)
+	if (!indio_dev)
 		return -ENOMEM;
 
 	st = iio_priv(indio_dev);
drivers/staging/iio/adc/mxs-lradc.c +5 -5
index 3f7715c..88bd084 100644
@@ -566,7 +566,7 @@ static unsigned mxs_lradc_read_ts_pressure(struct mxs_lradc *lradc,
 	m1 = mxs_lradc_read_raw_channel(lradc, ch1);
 	m2 = mxs_lradc_read_raw_channel(lradc, ch2);
 
-	if (m2 == 0) {
+	if (!m2) {
 		dev_warn(lradc->dev, "Cannot calculate pressure\n");
 		return 1 << (LRADC_RESOLUTION - 1);
 	}
@@ -1217,7 +1217,7 @@ static int mxs_lradc_trigger_init(struct iio_dev *iio)
 	struct mxs_lradc *lradc = iio_priv(iio);
 
 	trig = iio_trigger_alloc("%s-dev%i", iio->name, iio->id);
-	if (trig == NULL)
+	if (!trig)
 		return -ENOMEM;
 
 	trig->dev.parent = lradc->dev;
@@ -1608,14 +1608,14 @@ static int mxs_lradc_probe(struct platform_device *pdev)
 		return PTR_ERR(lradc->clk);
 	}
 	ret = clk_prepare_enable(lradc->clk);
-	if (ret != 0) {
+	if (ret) {
 		dev_err(dev, "Failed to enable the delay unit clock\n");
 		return ret;
 	}
 
 	touch_ret = mxs_lradc_probe_touchscreen(lradc, node);
 
-	if (touch_ret == 0)
+	if (!touch_ret)
 		lradc->buffer_vchans = BUFFER_VCHANS_LIMITED;
 	else
 		lradc->buffer_vchans = BUFFER_VCHANS_ALL;
@@ -1692,7 +1692,7 @@ static int mxs_lradc_probe(struct platform_device *pdev)
 		goto err_dev;
 
 	/* Register the touchscreen input device. */
-	if (touch_ret == 0) {
+	if (!touch_ret) {
 		ret = mxs_lradc_ts_register(lradc);
 		if (ret)
 			goto err_ts_register;
drivers/staging/iio/adc/spear_adc.c +1 -1
index c538237..d721242 100644
@@ -192,7 +192,7 @@ static int spear_adc_write_raw(struct iio_dev *indio_dev,
 
 	if ((val < SPEAR_ADC_CLK_MIN) ||
 		(val > SPEAR_ADC_CLK_MAX) ||
-		(val2 != 0)) {
+		val2) {
 		ret = -EINVAL;
 		goto out;
 	}
Signature · 1 line
1.9.1
#16 lore raw

PATCH v2 2/9 staging: iio: light: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL

---
 drivers/staging/iio/light/isl29018.c     | 4 ++--
 drivers/staging/iio/light/tsl2583.c      | 6 +++---
 drivers/staging/iio/light/tsl2x7x_core.c | 6 +++---
 3 files changed, 8 insertions(+), 8 deletions(-)
drivers/staging/iio/light/isl29018.c +2 -2
index 019ba52..73109dd 100644
@@ -370,7 +370,7 @@ static int isl29018_write_raw(struct iio_dev *indio_dev,
 		break;
 	case IIO_CHAN_INFO_INT_TIME:
 		if (chan->type == IIO_LIGHT) {
-			if (val != 0) {
+			if (val) {
 				mutex_unlock(&chip->lock);
 				return -EINVAL;
 			}
@@ -716,7 +716,7 @@ static int isl29018_probe(struct i2c_client *client,
 	int dev_id = 0;
 
 	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*chip));
-	if (indio_dev == NULL) {
+	if (!indio_dev) {
 		dev_err(&client->dev, "iio allocation fails\n");
 		return -ENOMEM;
 	}
drivers/staging/iio/light/tsl2583.c +3 -3
index df60203..3100d96 100644
@@ -263,7 +263,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
 	if ((ch0 >= chip->als_saturation) || (ch1 >= chip->als_saturation))
 		goto return_max;
 
-	if (ch0 == 0) {
+	if (!ch0) {
 		/* have no data, so return LAST VALUE */
 		ret = chip->als_cur_info.lux = 0;
 		goto out_unlock;
@@ -415,7 +415,7 @@ static int taos_chip_on(struct iio_dev *indio_dev)
 
 	/* determine als integration register */
 	als_count = (chip->taos_settings.als_time * 100 + 135) / 270;
-	if (als_count == 0)
+	if (!als_count)
 		als_count = 1; /* ensure at least one cycle */
 
 	/* convert back to time (encompasses overrides) */
@@ -499,7 +499,7 @@ static ssize_t taos_power_state_store(struct device *dev,
 	if (kstrtoint(buf, 0, &value))
 		return -EINVAL;
 
-	if (value == 0)
+	if (!value)
 		taos_chip_off(indio_dev);
 	else
 		taos_chip_on(indio_dev);
drivers/staging/iio/light/tsl2x7x_core.c +3 -3
index 010e607..c43bab9 100644
@@ -403,7 +403,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev)
 		goto return_max;
 	}
 
-	if (ch0 == 0) {
+	if (!ch0) {
 		/* have no data, so return LAST VALUE */
 		ret = chip->als_cur_info.lux;
 		goto out_unlock;
@@ -678,7 +678,7 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
 
 	/* determine als integration register */
 	als_count = (chip->tsl2x7x_settings.als_time * 100 + 135) / 270;
-	if (als_count == 0)
+	if (!als_count)
 		als_count = 1; /* ensure at least one cycle */
 
 	/* convert back to time (encompasses overrides) */
@@ -825,7 +825,7 @@ void tsl2x7x_prox_calculate(int *data, int length,
 	int sample_sum;
 	int tmp;
 
-	if (length == 0)
+	if (!length)
 		length = 1;
 
 	sample_sum = 0;
Signature · 1 line
1.9.1
#17 lore raw

PATCH v2 3/9 staging: iio: meter: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL

---
 drivers/staging/iio/meter/ade7753.c     | 2 +-
 drivers/staging/iio/meter/ade7754.c     | 2 +-
 drivers/staging/iio/meter/ade7759.c     | 2 +-
 drivers/staging/iio/meter/ade7854-spi.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
drivers/staging/iio/meter/ade7753.c +1 -1
index 3d2e50c..188830d 100644
@@ -406,7 +406,7 @@ static ssize_t ade7753_write_frequency(struct device *dev,
 	ret = kstrtou16(buf, 10, &val);
 	if (ret)
 		return ret;
-	if (val == 0)
+	if (!val)
 		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
drivers/staging/iio/meter/ade7754.c +1 -1
index 8552c76..664c6e5 100644
@@ -438,7 +438,7 @@ static ssize_t ade7754_write_frequency(struct device *dev,
 	ret = kstrtou16(buf, 10, &val);
 	if (ret)
 		return ret;
-	if (val == 0)
+	if (!val)
 		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
drivers/staging/iio/meter/ade7759.c +1 -1
index 23e7392..11c1edc 100644
@@ -377,7 +377,7 @@ static ssize_t ade7759_write_frequency(struct device *dev,
 	ret = kstrtou16(buf, 10, &val);
 	if (ret)
 		return ret;
-	if (val == 0)
+	if (!val)
 		return -EINVAL;
 
 	mutex_lock(&indio_dev->mlock);
drivers/staging/iio/meter/ade7854-spi.c +1 -1
index 9b255a5..da77486 100644
@@ -278,7 +278,7 @@ static int ade7854_spi_probe(struct spi_device *spi)
 	struct iio_dev *indio_dev;
 
 	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
-	if (indio_dev == NULL)
+	if (!indio_dev)
 		return -ENOMEM;
 	st = iio_priv(indio_dev);
 	spi_set_drvdata(spi, indio_dev);
Signature · 1 line
1.9.1
#18 lore raw

PATCH v2 4/9 staging: iio: accel: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL

---
 drivers/staging/iio/accel/sca3000_ring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/accel/sca3000_ring.c +1 -1
index 23685e7..6d19e12 100644
@@ -267,7 +267,7 @@ int sca3000_configure_ring(struct iio_dev *indio_dev)
 	struct iio_buffer *buffer;
 
 	buffer = sca3000_rb_allocate(indio_dev);
-	if (buffer == NULL)
+	if (!buffer)
 		return -ENOMEM;
 	indio_dev->modes |= INDIO_BUFFER_HARDWARE;
 
Signature · 1 line
1.9.1
#19 lore raw

PATCH v2 5/9 staging: iio: cdc: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL

---
 drivers/staging/iio/cdc/ad7150.c | 2 +-
 drivers/staging/iio/cdc/ad7152.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/staging/iio/cdc/ad7150.c +1 -1
index ff83394..9ba8f46 100644
@@ -222,7 +222,7 @@ static int ad7150_write_event_config(struct iio_dev *indio_dev,
 	u64 event_code;
 
 	/* Something must always be turned on */
-	if (state == 0)
+	if (!state)
 		return -EINVAL;
 
 	event_code = IIO_UNMOD_EVENT_CODE(chan->type, chan->channel, type, dir);
drivers/staging/iio/cdc/ad7152.c +1 -1
index c3d5531..485d0a5 100644
@@ -290,7 +290,7 @@ static int ad7152_write_raw(struct iio_dev *indio_dev,
 		ret = 0;
 		break;
 	case IIO_CHAN_INFO_SCALE:
-		if (val != 0) {
+		if (val) {
 			ret = -EINVAL;
 			goto out;
 		}
Signature · 1 line
1.9.1
#20 lore raw

PATCH v2 6/9 staging: iio: frequency: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL

---
 drivers/staging/iio/frequency/ad9834.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/frequency/ad9834.c +1 -1
index d02bb44..fcffe2c 100644
@@ -111,7 +111,7 @@ static ssize_t ad9834_write(struct device *dev,
 		break;
 	case AD9834_FSEL:
 	case AD9834_PSEL:
-		if (val == 0) {
+		if (!val) {
 			st->control &= ~(this_attr->address | AD9834_PIN_SW);
 		} else if (val == 1) {
 			st->control |= this_attr->address;
Signature · 1 line
1.9.1
#21 lore raw

PATCH v2 7/9 staging: iio: trigger: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL

---
 drivers/staging/iio/trigger/iio-trig-bfin-timer.c   | 4 ++--
 drivers/staging/iio/trigger/iio-trig-periodic-rtc.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/staging/iio/trigger/iio-trig-bfin-timer.c +2 -2
index 9fe48ef..035dd45 100644
@@ -100,7 +100,7 @@ static ssize_t iio_bfin_tmr_frequency_store(struct device *dev,
 	if (enabled)
 		disable_gptimers(st->t->bit);
 
-	if (val == 0)
+	if (!val)
 		return count;
 
 	val = get_sclk() / val;
@@ -125,7 +125,7 @@ static ssize_t iio_bfin_tmr_frequency_show(struct device *dev,
 	unsigned int period = get_gptimer_period(st->t->id);
 	unsigned long val;
 
-	if (period == 0)
+	if (!period)
 		val = 0;
 	else
 		val = get_sclk() / get_gptimer_period(st->t->id);
drivers/staging/iio/trigger/iio-trig-periodic-rtc.c +1 -1
index 2db8857..00d1393 100644
@@ -39,7 +39,7 @@ static int iio_trig_periodic_rtc_set_state(struct iio_trigger *trig, bool state)
 	dev_dbg(&trig_info->rtc->dev, "trigger frequency is %u\n",
 		trig_info->frequency);
 	ret = rtc_irq_set_state(trig_info->rtc, &trig_info->task, state);
-	if (ret == 0)
+	if (!ret)
 		trig_info->state = state;
 
 	return ret;
Signature · 1 line
1.9.1
#22 lore raw

PATCH v2 8/9 staging: iio: gyro: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL

---
 drivers/staging/iio/gyro/adis16060_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/gyro/adis16060_core.c +1 -1
index 4c5869d..80783e7 100644
@@ -67,7 +67,7 @@ static int adis16060_spi_read(struct iio_dev *indio_dev, u16 *val)
 	 * starts to place data MSB first on the DOUT line at
 	 * the 6th falling edge of SCLK
 	 */
-	if (ret == 0)
+	if (!ret)
 		*val = ((st->buf[0] & 0x3) << 12) |
 			(st->buf[1] << 4) |
 			((st->buf[2] >> 4) & 0xF);
Signature · 1 line
1.9.1
#23 lore raw

PATCH v2 9/9 staging: iio: magnetometer: Remove explicit comparisons

In reply to Cristina Moraru

Remove comparisons to 0 or NULL

---
 drivers/staging/iio/magnetometer/hmc5843_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/iio/magnetometer/hmc5843_core.c +1 -1
index 4aab022..394bc14 100644
@@ -334,7 +334,7 @@ static int hmc5843_get_scale_index(struct hmc5843_data *data, int val, int val2)
 {
 	int i;
 
-	if (val != 0)
+	if (val)
 		return -EINVAL;
 
 	for (i = 0; i < data->variant->n_regval_to_nanoscale; i++)
Signature · 1 line
1.9.1