Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] media: mem2mem: eliminate possible NULL pointer dereference

This patch removes the possible NULL pointer dereference in mem2mem
code.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
CC: Pawel Osciak <pawel@osciak.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>

authored by

Andrzej Pietrasiewicz and committed by
Mauro Carvalho Chehab
a6bd62be 1d0c86ca

+10 -8
+10 -8
drivers/media/video/v4l2-mem2mem.c
··· 97 97 98 98 spin_lock_irqsave(&q_ctx->rdy_spinlock, flags); 99 99 100 - if (list_empty(&q_ctx->rdy_queue)) 101 - goto end; 100 + if (list_empty(&q_ctx->rdy_queue)) { 101 + spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags); 102 + return NULL; 103 + } 102 104 103 105 b = list_entry(q_ctx->rdy_queue.next, struct v4l2_m2m_buffer, list); 104 - end: 105 106 spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags); 106 107 return &b->vb; 107 108 } ··· 118 117 unsigned long flags; 119 118 120 119 spin_lock_irqsave(&q_ctx->rdy_spinlock, flags); 121 - if (!list_empty(&q_ctx->rdy_queue)) { 122 - b = list_entry(q_ctx->rdy_queue.next, struct v4l2_m2m_buffer, 123 - list); 124 - list_del(&b->list); 125 - q_ctx->num_rdy--; 120 + if (list_empty(&q_ctx->rdy_queue)) { 121 + spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags); 122 + return NULL; 126 123 } 124 + b = list_entry(q_ctx->rdy_queue.next, struct v4l2_m2m_buffer, list); 125 + list_del(&b->list); 126 + q_ctx->num_rdy--; 127 127 spin_unlock_irqrestore(&q_ctx->rdy_spinlock, flags); 128 128 129 129 return &b->vb;