Skip to contentSkip to conversation

relay: check array offset before using it

PATCH New [email protected] 1 participant 1 message Dec 14, 2016 Relay

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 33/114 relay: check array offset before using it

From: Dan Carpenter <[email protected]>
Subject: relay: check array offset before using it

Smatch complains that we started using the array offset before we checked that it was valid.

Fixes 017c59c042d0 ('relay: Use per CPU constructs for the relay channel buffer pointers')

---

 kernel/relay.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/relay.c renamed from kernel/relay.c~relay-check-array-offset-before-using-it +2 -2
diff -puN kernel/relay.c~relay-check-array-offset-before-using-it kernel/relay.c
@@ -809,11 +809,11 @@ void relay_subbufs_consumed(struct rchan
 {
 	struct rchan_buf *buf;
 
-	if (!chan)
+	if (!chan || cpu >= NR_CPUS)
 		return;
 
 	buf = *per_cpu_ptr(chan->buf, cpu);
-	if (cpu >= NR_CPUS || !buf || subbufs_consumed > chan->n_subbufs)
+	if (!buf || subbufs_consumed > chan->n_subbufs)
 		return;
 
 	if (subbufs_consumed > buf->subbufs_produced - buf->subbufs_consumed)

_