Skip to content

Commit

Permalink
[media] ir-raw: Check available elements in kfifo before adding
Browse files Browse the repository at this point in the history
This patch adds an additional availability check in ir_raw_event_store
before adding an ir_raw_event into kfifo. The reason to do this is,
Kfifo_alloc allocates fifo of size rounded down to 2. Which in this
case makes sizeof ir_raw_event*MAX_IR_EVENT_SIZE = 6144 to 4096 bytes.
Then again 4096 is not perfectly divisable by sizeof ir_raw_event(12).
So before adding any element to kfifo checking howmany elements can be
inserted into fifo is safe.

This patch will make sure it inserts only sizeof(ev) into kfifo.

Without this patch ir_raw_event_thread will trigger a bug.

 kernel BUG at drivers/media/rc/ir-raw.c:65!
 Internal error: Oops - undefined instruction: 0 [#1] PREEMPT SMP
 Modules linked in:
 CPU: 0    Not tainted  (3.2.2_stm24_0208-b2000+ torvalds#31)
 PC is at ir_raw_event_thread+0xa4/0x10c
 LR is at ir_raw_event_thread+0xa4/0x10c
 pc : [<c01e0ef4>]    lr : [<c01e0ef4>]    psr: 60000013
 sp : df1d1f78  ip : df1d0000  fp : 00000004
 r10: 00000000  r9 : c041389c  r8 : c0413848
 r7 : df1d1f7c  r6 : df1b6ecc  r5 : df1b6ec0  r4 : df1d0000
 r3 : 0000000c  r2 : df1d1f6c  r1 : c0360798  r0 : 0000002f
 Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment kernel
 Control: 10c53c7d  Table: 5ece804a  DAC: 00000015
 Process rc0 (pid: 577, stack limit = 0xdf1d02f0)

This bug was identified as part of
https://bugzilla.stlinux.com/show_bug.cgi?id=17387 triage.

Signed-off-by: Srinivas Kandagatla <[email protected]>
Cc: [email protected]
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
Srinivas-Kandagatla authored and Mauro Carvalho Chehab committed Apr 10, 2012
1 parent ed0ee0c commit 24a19bc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/media/rc/ir-raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ int ir_raw_event_store(struct rc_dev *dev, struct ir_raw_event *ev)
IR_dprintk(2, "sample: (%05dus %s)\n",
TO_US(ev->duration), TO_STR(ev->pulse));

if (kfifo_in(&dev->raw->kfifo, ev, sizeof(*ev)) != sizeof(*ev))
if (kfifo_avail(&dev->raw->kfifo) >= sizeof(*ev))
kfifo_in(&dev->raw->kfifo, ev, sizeof(*ev));
else
return -ENOMEM;

return 0;
Expand Down

0 comments on commit 24a19bc

Please sign in to comment.