Skip to contentSkip to conversation

MIPS: irixelf: fix test unsigned var < 0

PATCH Applied Roel Kluin 6 participants 10 messages Apr 16, 2008 – Apr 21, 2008

Subsystems (5)
Networking Sound MIPS netfilter +1 more subsystems
lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/6 MIPS: irixelf: fix test unsigned var < 0

v is unsigned, cast to signed to evaluate the do_brk() return value,

---

arch/mips/kernel/irixelf.c +1 -1
index 290d8e3..fad2a2a 100644
@@ -583,15 +583,15 @@ static void irix_map_prda_page(void)
 	unsigned long v;
 	struct prda *pp;
 
 	down_write(&current->mm->mmap_sem);
 	v =  do_brk(PRDA_ADDRESS, PAGE_SIZE);
 	up_write(&current->mm->mmap_sem);
 
-	if (v < 0)
+	if ((long) v < 0)
 		return;
 
 	pp = (struct prda *) v;
 	pp->prda_sys.t_pid  = task_pid_vnr(current);
 	pp->prda_sys.t_prid = read_c0_prid();
 	pp->prda_sys.t_rpid = task_pid_vnr(current);
 
author
#1 lore raw

New_alarm is unsigned so the test didn't work.

---

drivers/rtc/rtc-ds1374.c +3 -3
index 45bda18..119bdc9 100644
@@ -216,16 +216,16 @@ static int ds1374_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 	rtc_tm_to_time(&alarm->time, &new_alarm);
 	rtc_tm_to_time(&now, &itime);
 
-	new_alarm -= itime;
-
 	/* This can happen due to races, in addition to dates that are
 	 * truly in the past.  To avoid requiring the caller to check for
 	 * races, dates in the past are assumed to be in the recent past
 	 * (i.e. not something that we'd rather the caller know about via
 	 * an error), and the alarm is set to go off as soon as possible.
 	 */
-	if (new_alarm <= 0)
+	if (new_alarm <= itime)
 		new_alarm = 1;
+	else
+		new_alarm -= itime;
 
 	mutex_lock(&ds1374->mutex);
 
author
#2 lore raw

PATCH 4/6 RTC: rtc-ds1374: fix unsigned new_alarm test

Sorry for the duplicate, I forgot to fix the email header
---
New_alarm is unsigned so the test didn't work.

---

drivers/rtc/rtc-ds1374.c +3 -3
index 45bda18..119bdc9 100644
@@ -216,16 +216,16 @@ static int ds1374_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
 	rtc_tm_to_time(&alarm->time, &new_alarm);
 	rtc_tm_to_time(&now, &itime);
 
-	new_alarm -= itime;
-
 	/* This can happen due to races, in addition to dates that are
 	 * truly in the past.  To avoid requiring the caller to check for
 	 * races, dates in the past are assumed to be in the recent past
 	 * (i.e. not something that we'd rather the caller know about via
 	 * an error), and the alarm is set to go off as soon as possible.
 	 */
-	if (new_alarm <= 0)
+	if (new_alarm <= itime)
 		new_alarm = 1;
+	else
+		new_alarm -= itime;
 
 	mutex_lock(&ds1374->mutex);
 
author
#4 lore raw

PATCH 5/6 NETFILTER: signed tcphoff for ipv6_skip_exthdr() retval

In reply to Roel Kluin

if tcphoff remains unsigned, a negative ipv6_skip_exthdr() return value will go unnoticed,

---

net/netfilter/xt_TCPOPTSTRIP.c +1 -1
index 3b2aa56..9685b6f 100644
@@ -90,7 +90,7 @@ tcpoptstrip_tg6(struct sk_buff *skb, const struct net_device *in,
 		const struct xt_target *target, const void *targinfo)
 {
 	struct ipv6hdr *ipv6h = ipv6_hdr(skb);
-	unsigned int tcphoff;
+	int tcphoff;
 	u_int8_t nexthdr;
 
 	nexthdr = ipv6h->nexthdr;
author
#6 lore raw

PATCH 6/6 sound/drivers/dummy.c: fix negative snd_pcm_format_width() check

In reply to Roel Kluin

bps is unsigned, a negative snd_pcm_format_width() return value is not noticed

---

sound/drivers/dummy.c +5 -4
index a240eae..1c88977 100644
@@ -230,13 +230,14 @@ static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct snd_dummy_pcm *dpcm = runtime->private_data;
-	unsigned int bps;
+	int bps;
+
+	bps = snd_pcm_format_width(runtime->format) * runtime->rate *
+		runtime->channels / 8;
 
-	bps = runtime->rate * runtime->channels;
-	bps *= snd_pcm_format_width(runtime->format);
-	bps /= 8;
 	if (bps <= 0)
 		return -EINVAL;
+
 	dpcm->pcm_bps = bps;
 	dpcm->pcm_jiffie = bps / HZ;
 	dpcm->pcm_size = snd_pcm_lib_buffer_bytes(substream);
Applied
#7 lore raw

Re: [alsa-devel] [PATCH 6/6] sound/drivers/dummy.c: fix negative snd_pcm_format_width() check

At Wed, 16 Apr 2008 18:20:33 +0200,

Quoted 4 lines · Roel Kluin

bps is unsigned, a negative snd_pcm_format_width() return value is not noticed

Applied to ALSA tree. Thanks.

Takashi

Quoted 29 lines

---

sound/drivers/dummy.c +5 -4
index a240eae..1c88977 100644
@@ -230,13 +230,14 @@ static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream)
 {
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct snd_dummy_pcm *dpcm = runtime->private_data;
-	unsigned int bps;
+	int bps;
+
+	bps = snd_pcm_format_width(runtime->format) * runtime->rate *
+		runtime->channels / 8;
 
-	bps = runtime->rate * runtime->channels;
-	bps *= snd_pcm_format_width(runtime->format);
-	bps /= 8;
 	if (bps <= 0)
 		return -EINVAL;
+
 	dpcm->pcm_bps = bps;
 	dpcm->pcm_jiffie = bps / HZ;
 	dpcm->pcm_size = snd_pcm_lib_buffer_bytes(substream);

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#8 lore raw
In reply to Roel Kluin
Quoted 1 line · Roel Kluin

v is unsigned, cast to signed to evaluate the do_brk() return value,

do_brk() is expected to return its first argument as the result in case of success. An error also wasn't getting propagated so some further fixes were needed for irix_map_prda_page and its caller. So I'll apply a different fix.

Thanks!

Ralf

#9 lore raw
In reply to Roel Kluin
Quoted 9 lines · Roel Kluin

v is unsigned, cast to signed to evaluate the do_brk() return value,

---

arch/mips/kernel/irixelf.c +0 -0
index 290d8e3..fad2a2a 100644

arch/mips/kernel/irixelf.c static void irix_map_prda_page(void) · line 590

Quoted 9 lines
arch/mips/kernel/irixelf.c +1 -1
@@ -583,15 +583,15 @@ static void irix_map_prda_page(void)
 	unsigned long v;
 	struct prda *pp;
 
 	down_write(&current->mm->mmap_sem);
 	v =  do_brk(PRDA_ADDRESS, PAGE_SIZE);
 	up_write(&current->mm->mmap_sem);
 
-	if (v < 0)
+	if ((long) v < 0)

maybe cast it earlier (to struct prda *) and check error with IS_ERR?

Quoted 13 lines
arch/mips/kernel/irixelf.c +0 -1
 		return;
 
 	pp = (struct prda *) v;
 	pp->prda_sys.t_pid  = task_pid_vnr(current);
 	pp->prda_sys.t_prid = read_c0_prid();
 	pp->prda_sys.t_rpid = task_pid_vnr(current);
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#5 lore raw

Re: [netfilter-core] [PATCH 5/6] NETFILTER: signed tcphoff for ipv6_skip_exthdr() retval

In reply to Roel Kluin
Quoted 2 lines · Roel Kluin

if tcphoff remains unsigned, a negative ipv6_skip_exthdr() return value will go unnoticed,

Applied, thanks.