diff options
Diffstat (limited to 'drivers/media/usb/pvrusb2/pvrusb2-io.c')
| -rw-r--r-- | drivers/media/usb/pvrusb2/pvrusb2-io.c | 211 |
1 files changed, 94 insertions, 117 deletions
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-io.c b/drivers/media/usb/pvrusb2/pvrusb2-io.c index 1e354747de3f..28ffe7981f8c 100644 --- a/drivers/media/usb/pvrusb2/pvrusb2-io.c +++ b/drivers/media/usb/pvrusb2/pvrusb2-io.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * - * * Copyright (C) 2005 Mike Isely <isely@pobox.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * */ #include "pvrusb2-io.h" @@ -37,13 +23,13 @@ static const char *pvr2_buffer_state_decode(enum pvr2_buffer_state); if ((bp)->signature != BUFFER_SIG) { \ pvr2_trace(PVR2_TRACE_ERROR_LEGS, \ "Buffer %p is bad at %s:%d", \ - (bp),__FILE__,__LINE__); \ - pvr2_buffer_describe(bp,"BadSig"); \ + (bp), __FILE__, __LINE__); \ + pvr2_buffer_describe(bp, "BadSig"); \ BUG(); \ } \ } while (0) #else -#define BUFFER_CHECK(bp) do {} while(0) +#define BUFFER_CHECK(bp) do {} while (0) #endif struct pvr2_stream { @@ -110,11 +96,10 @@ static const char *pvr2_buffer_state_decode(enum pvr2_buffer_state st) } #ifdef SANITY_CHECK_BUFFERS -static void pvr2_buffer_describe(struct pvr2_buffer *bp,const char *msg) +static void pvr2_buffer_describe(struct pvr2_buffer *bp, const char *msg) { pvr2_trace(PVR2_TRACE_INFO, - "buffer%s%s %p state=%s id=%d status=%d" - " stream=%p purb=%p sig=0x%x", + "buffer%s%s %p state=%s id=%d status=%d stream=%p purb=%p sig=0x%x", (msg ? " " : ""), (msg ? msg : ""), bp, @@ -156,9 +141,8 @@ static void pvr2_buffer_remove(struct pvr2_buffer *bp) (*cnt)--; (*bcnt) -= ccnt; pvr2_trace(PVR2_TRACE_BUF_FLOW, - "/*---TRACE_FLOW---*/" - " bufferPool %8s dec cap=%07d cnt=%02d", - pvr2_buffer_state_decode(bp->state),*bcnt,*cnt); + "/*---TRACE_FLOW---*/ bufferPool %8s dec cap=%07d cnt=%02d", + pvr2_buffer_state_decode(bp->state), *bcnt, *cnt); bp->state = pvr2_buffer_state_none; } @@ -173,9 +157,9 @@ static void pvr2_buffer_set_none(struct pvr2_buffer *bp) bp, pvr2_buffer_state_decode(bp->state), pvr2_buffer_state_decode(pvr2_buffer_state_none)); - spin_lock_irqsave(&sp->list_lock,irq_flags); + spin_lock_irqsave(&sp->list_lock, irq_flags); pvr2_buffer_remove(bp); - spin_unlock_irqrestore(&sp->list_lock,irq_flags); + spin_unlock_irqrestore(&sp->list_lock, irq_flags); } static int pvr2_buffer_set_ready(struct pvr2_buffer *bp) @@ -190,19 +174,18 @@ static int pvr2_buffer_set_ready(struct pvr2_buffer *bp) bp, pvr2_buffer_state_decode(bp->state), pvr2_buffer_state_decode(pvr2_buffer_state_ready)); - spin_lock_irqsave(&sp->list_lock,irq_flags); + spin_lock_irqsave(&sp->list_lock, irq_flags); fl = (sp->r_count == 0); pvr2_buffer_remove(bp); - list_add_tail(&bp->list_overhead,&sp->ready_list); + list_add_tail(&bp->list_overhead, &sp->ready_list); bp->state = pvr2_buffer_state_ready; (sp->r_count)++; sp->r_bcount += bp->used_count; pvr2_trace(PVR2_TRACE_BUF_FLOW, - "/*---TRACE_FLOW---*/" - " bufferPool %8s inc cap=%07d cnt=%02d", + "/*---TRACE_FLOW---*/ bufferPool %8s inc cap=%07d cnt=%02d", pvr2_buffer_state_decode(bp->state), - sp->r_bcount,sp->r_count); - spin_unlock_irqrestore(&sp->list_lock,irq_flags); + sp->r_bcount, sp->r_count); + spin_unlock_irqrestore(&sp->list_lock, irq_flags); return fl; } @@ -217,18 +200,17 @@ static void pvr2_buffer_set_idle(struct pvr2_buffer *bp) bp, pvr2_buffer_state_decode(bp->state), pvr2_buffer_state_decode(pvr2_buffer_state_idle)); - spin_lock_irqsave(&sp->list_lock,irq_flags); + spin_lock_irqsave(&sp->list_lock, irq_flags); pvr2_buffer_remove(bp); - list_add_tail(&bp->list_overhead,&sp->idle_list); + list_add_tail(&bp->list_overhead, &sp->idle_list); bp->state = pvr2_buffer_state_idle; (sp->i_count)++; sp->i_bcount += bp->max_count; pvr2_trace(PVR2_TRACE_BUF_FLOW, - "/*---TRACE_FLOW---*/" - " bufferPool %8s inc cap=%07d cnt=%02d", + "/*---TRACE_FLOW---*/ bufferPool %8s inc cap=%07d cnt=%02d", pvr2_buffer_state_decode(bp->state), - sp->i_bcount,sp->i_count); - spin_unlock_irqrestore(&sp->list_lock,irq_flags); + sp->i_bcount, sp->i_count); + spin_unlock_irqrestore(&sp->list_lock, irq_flags); } static void pvr2_buffer_set_queued(struct pvr2_buffer *bp) @@ -242,18 +224,17 @@ static void pvr2_buffer_set_queued(struct pvr2_buffer *bp) bp, pvr2_buffer_state_decode(bp->state), pvr2_buffer_state_decode(pvr2_buffer_state_queued)); - spin_lock_irqsave(&sp->list_lock,irq_flags); + spin_lock_irqsave(&sp->list_lock, irq_flags); pvr2_buffer_remove(bp); - list_add_tail(&bp->list_overhead,&sp->queued_list); + list_add_tail(&bp->list_overhead, &sp->queued_list); bp->state = pvr2_buffer_state_queued; (sp->q_count)++; sp->q_bcount += bp->max_count; pvr2_trace(PVR2_TRACE_BUF_FLOW, - "/*---TRACE_FLOW---*/" - " bufferPool %8s inc cap=%07d cnt=%02d", + "/*---TRACE_FLOW---*/ bufferPool %8s inc cap=%07d cnt=%02d", pvr2_buffer_state_decode(bp->state), - sp->q_bcount,sp->q_count); - spin_unlock_irqrestore(&sp->list_lock,irq_flags); + sp->q_bcount, sp->q_count); + spin_unlock_irqrestore(&sp->list_lock, irq_flags); } static void pvr2_buffer_wipe(struct pvr2_buffer *bp) @@ -267,18 +248,18 @@ static int pvr2_buffer_init(struct pvr2_buffer *bp, struct pvr2_stream *sp, unsigned int id) { - memset(bp,0,sizeof(*bp)); + memset(bp, 0, sizeof(*bp)); bp->signature = BUFFER_SIG; bp->id = id; pvr2_trace(PVR2_TRACE_BUF_POOL, - "/*---TRACE_FLOW---*/ bufferInit %p stream=%p",bp,sp); + "/*---TRACE_FLOW---*/ bufferInit %p stream=%p", bp, sp); bp->stream = sp; bp->state = pvr2_buffer_state_none; INIT_LIST_HEAD(&bp->list_overhead); - bp->purb = usb_alloc_urb(0,GFP_KERNEL); + bp->purb = usb_alloc_urb(0, GFP_KERNEL); if (! bp->purb) return -ENOMEM; #ifdef SANITY_CHECK_BUFFERS - pvr2_buffer_describe(bp,"create"); + pvr2_buffer_describe(bp, "create"); #endif return 0; } @@ -286,18 +267,18 @@ static int pvr2_buffer_init(struct pvr2_buffer *bp, static void pvr2_buffer_done(struct pvr2_buffer *bp) { #ifdef SANITY_CHECK_BUFFERS - pvr2_buffer_describe(bp,"delete"); + pvr2_buffer_describe(bp, "delete"); #endif pvr2_buffer_wipe(bp); pvr2_buffer_set_none(bp); bp->signature = 0; bp->stream = NULL; usb_free_urb(bp->purb); - pvr2_trace(PVR2_TRACE_BUF_POOL,"/*---TRACE_FLOW---*/" - " bufferDone %p",bp); + pvr2_trace(PVR2_TRACE_BUF_POOL, "/*---TRACE_FLOW---*/ bufferDone %p", + bp); } -static int pvr2_stream_buffer_count(struct pvr2_stream *sp,unsigned int cnt) +static int pvr2_stream_buffer_count(struct pvr2_stream *sp, unsigned int cnt) { int ret; unsigned int scnt; @@ -306,8 +287,7 @@ static int pvr2_stream_buffer_count(struct pvr2_stream *sp,unsigned int cnt) if (cnt == sp->buffer_total_count) return 0; pvr2_trace(PVR2_TRACE_BUF_POOL, - "/*---TRACE_FLOW---*/ poolResize " - " stream=%p cur=%d adj=%+d", + "/*---TRACE_FLOW---*/ poolResize stream=%p cur=%d adj=%+d", sp, sp->buffer_total_count, cnt-sp->buffer_total_count); @@ -318,10 +298,11 @@ static int pvr2_stream_buffer_count(struct pvr2_stream *sp,unsigned int cnt) if (cnt > sp->buffer_total_count) { if (scnt > sp->buffer_slot_count) { struct pvr2_buffer **nb; - nb = kmalloc(scnt * sizeof(*nb),GFP_KERNEL); + + nb = kmalloc_array(scnt, sizeof(*nb), GFP_KERNEL); if (!nb) return -ENOMEM; if (sp->buffer_slot_count) { - memcpy(nb,sp->buffers, + memcpy(nb, sp->buffers, sp->buffer_slot_count * sizeof(*nb)); kfree(sp->buffers); } @@ -330,9 +311,9 @@ static int pvr2_stream_buffer_count(struct pvr2_stream *sp,unsigned int cnt) } while (sp->buffer_total_count < cnt) { struct pvr2_buffer *bp; - bp = kmalloc(sizeof(*bp),GFP_KERNEL); + bp = kmalloc(sizeof(*bp), GFP_KERNEL); if (!bp) return -ENOMEM; - ret = pvr2_buffer_init(bp,sp,sp->buffer_total_count); + ret = pvr2_buffer_init(bp, sp, sp->buffer_total_count); if (ret) { kfree(bp); return -ENOMEM; @@ -354,8 +335,8 @@ static int pvr2_stream_buffer_count(struct pvr2_stream *sp,unsigned int cnt) if (scnt < sp->buffer_slot_count) { struct pvr2_buffer **nb = NULL; if (scnt) { - nb = kmemdup(sp->buffers, scnt * sizeof(*nb), - GFP_KERNEL); + nb = kmemdup_array(sp->buffers, scnt, sizeof(*nb), + GFP_KERNEL); if (!nb) return -ENOMEM; } kfree(sp->buffers); @@ -374,12 +355,11 @@ static int pvr2_stream_achieve_buffer_count(struct pvr2_stream *sp) if (sp->buffer_total_count == sp->buffer_target_count) return 0; pvr2_trace(PVR2_TRACE_BUF_POOL, - "/*---TRACE_FLOW---*/" - " poolCheck stream=%p cur=%d tgt=%d", - sp,sp->buffer_total_count,sp->buffer_target_count); + "/*---TRACE_FLOW---*/ poolCheck stream=%p cur=%d tgt=%d", + sp, sp->buffer_total_count, sp->buffer_target_count); if (sp->buffer_total_count < sp->buffer_target_count) { - return pvr2_stream_buffer_count(sp,sp->buffer_target_count); + return pvr2_stream_buffer_count(sp, sp->buffer_target_count); } cnt = 0; @@ -389,7 +369,7 @@ static int pvr2_stream_achieve_buffer_count(struct pvr2_stream *sp) cnt++; } if (cnt) { - pvr2_stream_buffer_count(sp,sp->buffer_total_count - cnt); + pvr2_stream_buffer_count(sp, sp->buffer_total_count - cnt); } return 0; @@ -400,7 +380,7 @@ static void pvr2_stream_internal_flush(struct pvr2_stream *sp) struct list_head *lp; struct pvr2_buffer *bp1; while ((lp = sp->queued_list.next) != &sp->queued_list) { - bp1 = list_entry(lp,struct pvr2_buffer,list_overhead); + bp1 = list_entry(lp, struct pvr2_buffer, list_overhead); pvr2_buffer_wipe(bp1); /* At this point, we should be guaranteed that no completion callback may happen on this buffer. But it's @@ -428,7 +408,7 @@ static void pvr2_stream_done(struct pvr2_stream *sp) { mutex_lock(&sp->mutex); do { pvr2_stream_internal_flush(sp); - pvr2_stream_buffer_count(sp,0); + pvr2_stream_buffer_count(sp, 0); } while (0); mutex_unlock(&sp->mutex); } @@ -443,8 +423,8 @@ static void buffer_complete(struct urb *urb) bp->status = 0; pvr2_trace(PVR2_TRACE_BUF_FLOW, "/*---TRACE_FLOW---*/ bufferComplete %p stat=%d cnt=%d", - bp,urb->status,urb->actual_length); - spin_lock_irqsave(&sp->list_lock,irq_flags); + bp, urb->status, urb->actual_length); + spin_lock_irqsave(&sp->list_lock, irq_flags); if ((!(urb->status)) || (urb->status == -ENOENT) || (urb->status == -ECONNRESET) || @@ -454,8 +434,8 @@ static void buffer_complete(struct urb *urb) bp->used_count = urb->actual_length; if (sp->fail_count) { pvr2_trace(PVR2_TRACE_TOLERANCE, - "stream %p transfer ok" - " - fail count reset",sp); + "stream %p transfer ok - fail count reset", + sp); sp->fail_count = 0; } } else if (sp->fail_count < sp->fail_tolerance) { @@ -464,16 +444,15 @@ static void buffer_complete(struct urb *urb) (sp->fail_count)++; (sp->buffers_failed)++; pvr2_trace(PVR2_TRACE_TOLERANCE, - "stream %p ignoring error %d" - " - fail count increased to %u", - sp,urb->status,sp->fail_count); + "stream %p ignoring error %d - fail count increased to %u", + sp, urb->status, sp->fail_count); } else { (sp->buffers_failed)++; bp->status = urb->status; } - spin_unlock_irqrestore(&sp->list_lock,irq_flags); + spin_unlock_irqrestore(&sp->list_lock, irq_flags); pvr2_buffer_set_ready(bp); - if (sp && sp->callback_func) { + if (sp->callback_func) { sp->callback_func(sp->callback_data); } } @@ -481,9 +460,9 @@ static void buffer_complete(struct urb *urb) struct pvr2_stream *pvr2_stream_create(void) { struct pvr2_stream *sp; - sp = kzalloc(sizeof(*sp),GFP_KERNEL); + sp = kzalloc(sizeof(*sp), GFP_KERNEL); if (!sp) return sp; - pvr2_trace(PVR2_TRACE_INIT,"pvr2_stream_create: sp=%p",sp); + pvr2_trace(PVR2_TRACE_INIT, "pvr2_stream_create: sp=%p", sp); pvr2_stream_init(sp); return sp; } @@ -491,7 +470,7 @@ struct pvr2_stream *pvr2_stream_create(void) void pvr2_stream_destroy(struct pvr2_stream *sp) { if (!sp) return; - pvr2_trace(PVR2_TRACE_INIT,"pvr2_stream_destroy: sp=%p",sp); + pvr2_trace(PVR2_TRACE_INIT, "pvr2_stream_destroy: sp=%p", sp); pvr2_stream_done(sp); kfree(sp); } @@ -506,7 +485,7 @@ void pvr2_stream_setup(struct pvr2_stream *sp, sp->dev = dev; sp->endpoint = endpoint; sp->fail_tolerance = tolerance; - } while(0); mutex_unlock(&sp->mutex); + } while (0); mutex_unlock(&sp->mutex); } void pvr2_stream_set_callback(struct pvr2_stream *sp, @@ -514,12 +493,14 @@ void pvr2_stream_set_callback(struct pvr2_stream *sp, void *data) { unsigned long irq_flags; - mutex_lock(&sp->mutex); do { - spin_lock_irqsave(&sp->list_lock,irq_flags); + mutex_lock(&sp->mutex); + do { + spin_lock_irqsave(&sp->list_lock, irq_flags); sp->callback_data = data; sp->callback_func = func; - spin_unlock_irqrestore(&sp->list_lock,irq_flags); - } while(0); mutex_unlock(&sp->mutex); + spin_unlock_irqrestore(&sp->list_lock, irq_flags); + } while (0); + mutex_unlock(&sp->mutex); } void pvr2_stream_get_stats(struct pvr2_stream *sp, @@ -527,7 +508,7 @@ void pvr2_stream_get_stats(struct pvr2_stream *sp, int zero_counts) { unsigned long irq_flags; - spin_lock_irqsave(&sp->list_lock,irq_flags); + spin_lock_irqsave(&sp->list_lock, irq_flags); if (stats) { stats->buffers_in_queue = sp->q_count; stats->buffers_in_idle = sp->i_count; @@ -541,7 +522,7 @@ void pvr2_stream_get_stats(struct pvr2_stream *sp, sp->buffers_failed = 0; sp->bytes_processed = 0; } - spin_unlock_irqrestore(&sp->list_lock,irq_flags); + spin_unlock_irqrestore(&sp->list_lock, irq_flags); } /* Query / set the nominal buffer count */ @@ -550,14 +531,16 @@ int pvr2_stream_get_buffer_count(struct pvr2_stream *sp) return sp->buffer_target_count; } -int pvr2_stream_set_buffer_count(struct pvr2_stream *sp,unsigned int cnt) +int pvr2_stream_set_buffer_count(struct pvr2_stream *sp, unsigned int cnt) { int ret; if (sp->buffer_target_count == cnt) return 0; - mutex_lock(&sp->mutex); do { + mutex_lock(&sp->mutex); + do { sp->buffer_target_count = cnt; ret = pvr2_stream_achieve_buffer_count(sp); - } while(0); mutex_unlock(&sp->mutex); + } while (0); + mutex_unlock(&sp->mutex); return ret; } @@ -565,17 +548,17 @@ struct pvr2_buffer *pvr2_stream_get_idle_buffer(struct pvr2_stream *sp) { struct list_head *lp = sp->idle_list.next; if (lp == &sp->idle_list) return NULL; - return list_entry(lp,struct pvr2_buffer,list_overhead); + return list_entry(lp, struct pvr2_buffer, list_overhead); } struct pvr2_buffer *pvr2_stream_get_ready_buffer(struct pvr2_stream *sp) { struct list_head *lp = sp->ready_list.next; if (lp == &sp->ready_list) return NULL; - return list_entry(lp,struct pvr2_buffer,list_overhead); + return list_entry(lp, struct pvr2_buffer, list_overhead); } -struct pvr2_buffer *pvr2_stream_get_buffer(struct pvr2_stream *sp,int id) +struct pvr2_buffer *pvr2_stream_get_buffer(struct pvr2_stream *sp, int id) { if (id < 0) return NULL; if (id >= sp->buffer_total_count) return NULL; @@ -590,7 +573,8 @@ int pvr2_stream_get_ready_count(struct pvr2_stream *sp) void pvr2_stream_kill(struct pvr2_stream *sp) { struct pvr2_buffer *bp; - mutex_lock(&sp->mutex); do { + mutex_lock(&sp->mutex); + do { pvr2_stream_internal_flush(sp); while ((bp = pvr2_stream_get_ready_buffer(sp)) != NULL) { pvr2_buffer_set_idle(bp); @@ -598,7 +582,8 @@ void pvr2_stream_kill(struct pvr2_stream *sp) if (sp->buffer_total_count != sp->buffer_target_count) { pvr2_stream_achieve_buffer_count(sp); } - } while(0); mutex_unlock(&sp->mutex); + } while (0); + mutex_unlock(&sp->mutex); } int pvr2_buffer_queue(struct pvr2_buffer *bp) @@ -612,7 +597,8 @@ int pvr2_buffer_queue(struct pvr2_buffer *bp) struct pvr2_stream *sp; if (!bp) return -EINVAL; sp = bp->stream; - mutex_lock(&sp->mutex); do { + mutex_lock(&sp->mutex); + do { pvr2_buffer_wipe(bp); if (!sp->dev) { ret = -EIO; @@ -630,25 +616,27 @@ int pvr2_buffer_queue(struct pvr2_buffer *bp) usb_fill_bulk_urb(bp->purb, // struct urb *urb sp->dev, // struct usb_device *dev // endpoint (below) - usb_rcvbulkpipe(sp->dev,sp->endpoint), + usb_rcvbulkpipe(sp->dev, sp->endpoint), bp->ptr, // void *transfer_buffer bp->max_count, // int buffer_length buffer_complete, bp); - usb_submit_urb(bp->purb,GFP_KERNEL); - } while(0); mutex_unlock(&sp->mutex); + usb_submit_urb(bp->purb, GFP_KERNEL); + } while (0); + mutex_unlock(&sp->mutex); return ret; } -int pvr2_buffer_set_buffer(struct pvr2_buffer *bp,void *ptr,unsigned int cnt) +int pvr2_buffer_set_buffer(struct pvr2_buffer *bp, void *ptr, unsigned int cnt) { int ret = 0; unsigned long irq_flags; struct pvr2_stream *sp; if (!bp) return -EINVAL; sp = bp->stream; - mutex_lock(&sp->mutex); do { - spin_lock_irqsave(&sp->list_lock,irq_flags); + mutex_lock(&sp->mutex); + do { + spin_lock_irqsave(&sp->list_lock, irq_flags); if (bp->state != pvr2_buffer_state_idle) { ret = -EPERM; } else { @@ -657,14 +645,14 @@ int pvr2_buffer_set_buffer(struct pvr2_buffer *bp,void *ptr,unsigned int cnt) bp->max_count = cnt; bp->stream->i_bcount += bp->max_count; pvr2_trace(PVR2_TRACE_BUF_FLOW, - "/*---TRACE_FLOW---*/ bufferPool " - " %8s cap cap=%07d cnt=%02d", + "/*---TRACE_FLOW---*/ bufferPool %8s cap cap=%07d cnt=%02d", pvr2_buffer_state_decode( pvr2_buffer_state_idle), - bp->stream->i_bcount,bp->stream->i_count); + bp->stream->i_bcount, bp->stream->i_count); } - spin_unlock_irqrestore(&sp->list_lock,irq_flags); - } while(0); mutex_unlock(&sp->mutex); + spin_unlock_irqrestore(&sp->list_lock, irq_flags); + } while (0); + mutex_unlock(&sp->mutex); return ret; } @@ -682,14 +670,3 @@ int pvr2_buffer_get_id(struct pvr2_buffer *bp) { return bp->id; } - - -/* - Stuff for Emacs to see, in order to encourage consistent editing style: - *** Local Variables: *** - *** mode: c *** - *** fill-column: 75 *** - *** tab-width: 8 *** - *** c-basic-offset: 8 *** - *** End: *** - */ |
