Skip to contentSkip to conversation

cpufreq-dt: fix handling regulator_get_voltage result

PATCH Applied Andrzej Hajda 3 participants 5 messages Dec 30, 2015 – Jan 5, 2016

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

PATCH 1/1 scsi_transport_fc: remove useless check

In reply to Andrzej Hajda

simple_strtoul returns only non-negative values and *val is unsigned so there is no possibility that *val is lesser than 0.

The problem has been detected using proposed semantic patch scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2038576

---
 drivers/scsi/scsi_transport_fc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/scsi_transport_fc.c +1 -1
index 8a88226..ecf62d9 100644
@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
 	char *cp;
 
 	*val = simple_strtoul(buf, &cp, 0);
-	if ((*cp && (*cp != '\n')) || (*val < 0))
+	if (*cp && (*cp != '\n'))
 		return -EINVAL;
 	/*
 	 * Check for overflow; dev_loss_tmo is u32
Signature · 1 line
1.9.1
#0 lore raw

PATCH 1/1 cpufreq-dt: fix handling regulator_get_voltage result

The function can return negative values so it should be assigned to signed type.

The problem has been detected using proposed semantic patch scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2038576

---
 drivers/cpufreq/cpufreq-dt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/cpufreq/cpufreq-dt.c +3 -2
index 1ceece9..9bc37c4 100644
@@ -50,7 +50,8 @@ static int set_target(struct cpufreq_policy *policy, unsigned int index)
 	struct private_data *priv = policy->driver_data;
 	struct device *cpu_dev = priv->cpu_dev;
 	struct regulator *cpu_reg = priv->cpu_reg;
-	unsigned long volt = 0, volt_old = 0, tol = 0;
+	unsigned long volt = 0, tol = 0;
+	int volt_old = 0;
 	unsigned int old_freq, new_freq;
 	long freq_Hz, freq_exact;
 	int ret;
@@ -83,7 +84,7 @@ static int set_target(struct cpufreq_policy *policy, unsigned int index)
 			opp_freq / 1000, volt);
 	}
 
-	dev_dbg(cpu_dev, "%u MHz, %ld mV --> %u MHz, %ld mV\n",
+	dev_dbg(cpu_dev, "%u MHz, %d mV --> %u MHz, %ld mV\n",
 		old_freq / 1000, (volt_old > 0) ? volt_old / 1000 : -1,
 		new_freq / 1000, volt ? volt / 1000 : -1);
 
Signature · 1 line
1.9.1
#2 lore raw

PATCH 1/1 staging: lustre: remove useless check

Variable reserved is unsigned so the check is always true.

The problem has been detected using proposed semantic patch scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].

[1]: http://permalink.gmane.org/gmane.linux.kernel/2038576

---
 drivers/staging/lustre/lustre/llite/rw.c | 1 -
 1 file changed, 1 deletion(-)
drivers/staging/lustre/lustre/llite/rw.c +0 -1
index 95cdb0c..2fd07a2 100644
@@ -764,7 +764,6 @@ int ll_readahead(const struct lu_env *env, struct cl_io *io,
 	ret = ll_read_ahead_pages(env, io, queue,
 				  ria, &reserved, mapping, &ra_end);
 
-	LASSERTF(reserved >= 0, "reserved %lu\n", reserved);
 	if (reserved != 0)
 		ll_ra_count_put(ll_i2sbi(inode), reserved);
 
Signature · 1 line
1.9.1
maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Andrzej Hajda
Quoted 6 lines · Andrzej Hajda

The function can return negative values so it should be assigned to signed type.

The problem has been detected using proposed semantic patch scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].

Quoted 6 lines

[1]: http://permalink.gmane.org/gmane.linux.kernel/2038576

---
 drivers/cpufreq/cpufreq-dt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Signature · 1 line
viresh
#4 lore raw
Quoted 7 lines · Viresh Kumar
Quoted 6 lines · Andrzej Hajda

The function can return negative values so it should be assigned to signed type.

The problem has been detected using proposed semantic patch scripts/coccinelle/tests/unsigned_lesser_than_zero.cocci [1].

Quoted 8 lines
Quoted 6 lines

[1]: http://permalink.gmane.org/gmane.linux.kernel/2038576

---
 drivers/cpufreq/cpufreq-dt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Applied, thanks!

Rafael