From patchwork Sun May 17 08:59:37 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uri Shkolnik X-Patchwork-Id: 24291 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n4H8uZ3o013425 for ; Sun, 17 May 2009 08:59:40 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753426AbZEQI7h (ORCPT ); Sun, 17 May 2009 04:59:37 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753869AbZEQI7g (ORCPT ); Sun, 17 May 2009 04:59:36 -0400 Received: from web110813.mail.gq1.yahoo.com ([67.195.13.236]:34240 "HELO web110813.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1753426AbZEQI7g (ORCPT ); Sun, 17 May 2009 04:59:36 -0400 Received: (qmail 30790 invoked by uid 60001); 17 May 2009 08:59:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1242550777; bh=e7iCMMlz5xiJPaDLH5mus5E4CunNsIasq3hmJboRj3o=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=eg3l/PTFPU8mjZNpj4bKyvJOT27bFaEVcW1wwcuGo2hc8XU/Z5A/6BCMFMzrzUn/ODeTOZAhuOZ5PlWZW2y9xFkFeWcXkY7VyHIJT7PmiNSBx6/NbadRzNuuNHUhFtdBl67fk6LcJ5s8B4cpuqV/dMWpUgNr+a5v7XIrto7JDFA= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=EiA8QrmFfQkTbu1kuKbSSQxwknURRN2Bd/Mo2EkRxyhdr8SMhUA1hNT0pgl5vjpNYIP2TbSGn4cWWKlqliN4+33OUaRTuiSlKERqgP+IMTVUQXxvv/HFCOT2ZguS6nADIn7S8CSjiMdke+Ql1sN4Xn6aVwEKDA578zQztktATEE=; Message-ID: <169030.30544.qm@web110813.mail.gq1.yahoo.com> X-YMail-OSG: ktur6iEVM1kVSXHh3Zfyrk9.bNrDaPaWxSenfHWDMTU5ahfjUi1mg5uoQgAVbLgwsIRVAOy2Dwd87TWsR2Aa5pK7zREUXVC5AYMSYEg2GnbW3Jbdn0fM1PdpZJjbypn3V28epp._BTfQdDCqxxKXAyW7d7_OB1bVk3vwP2RoJnefHE5u1bCICHH0uZi6OvN74k.Yr8J.MDN5_EIXM1b9lrwiFbkLkOddqD5QZC0BpIiWGHvf2s2A_aQ1INWbJdcMSxVyTgc4B1PLmZ1Jnu6fNnMnrNG.2E06Y_echeQbCaIOxVFH8YM55x21GtjxNwKADNlycgs2cdz._eClwqtmHH5u14a8xr2zMcmP_v97MdgsixianOY2J0oA1Q-- Received: from [199.203.99.233] by web110813.mail.gq1.yahoo.com via HTTP; Sun, 17 May 2009 01:59:37 PDT X-Mailer: YahooMailClassic/5.3.9 YahooMailWebService/0.7.289.10 Date: Sun, 17 May 2009 01:59:37 -0700 (PDT) From: Uri Shkolnik Subject: [PATCH] [0905_24] Siano: smscore - fix get_common_buffer bug To: LinuxML MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org # HG changeset patch # User Uri Shkolnik # Date 1242331867 -10800 # Node ID fc839f80e81fed027a4721f5c679b9af7e27c867 # Parent 415ca02f74b960c02ddfa7ee719cf87726d97490 [0905_24] Siano: smscore - fix get_common_buffer bug From: Uri Shkolnik get common buffers() should block operation until valid buffer is avaliable. Priority: normal Signed-off-by: Uri Shkolnik --- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff -r 415ca02f74b9 -r fc839f80e81f linux/drivers/media/dvb/siano/smscoreapi.c --- a/linux/drivers/media/dvb/siano/smscoreapi.c Thu May 14 23:02:05 2009 +0300 +++ b/linux/drivers/media/dvb/siano/smscoreapi.c Thu May 14 23:11:07 2009 +0300 @@ -30,6 +30,7 @@ #include #include +#include #include "smscoreapi.h" #include "smsendian.h" @@ -356,6 +357,9 @@ int smscore_register_device(struct smsde init_completion(&dev->gpio_set_level_done); init_completion(&dev->gpio_get_level_done); init_completion(&dev->ir_init_done); + + /* Buffer management */ + init_waitqueue_head(&dev->buffer_mng_waitq); /* alloc common buffer */ dev->common_buffer_size = params->buffer_size * params->num_buffers; @@ -694,7 +698,9 @@ void smscore_unregister_device(struct sm * onresponse must no longer be called */ while (1) { - while ((cb = smscore_getbuffer(coredev))) { + while (!list_empty(&coredev->buffers)) { + cb = (struct smscore_buffer_t *) coredev->buffers.next; + list_del(&cb->entry); kfree(cb); num_buffers++; } @@ -715,8 +721,10 @@ void smscore_unregister_device(struct sm if (coredev->common_buffer) dma_free_coherent(NULL, coredev->common_buffer_size, - coredev->common_buffer, - coredev->common_buffer_phys); + coredev->common_buffer, coredev->common_buffer_phys); + + if (coredev->fw_buf != NULL) + kfree(coredev->fw_buf); list_del(&coredev->entry); kfree(coredev); @@ -1105,12 +1113,24 @@ struct smscore_buffer_t *smscore_getbuff struct smscore_buffer_t *cb = NULL; unsigned long flags; + DEFINE_WAIT(wait); + spin_lock_irqsave(&coredev->bufferslock, flags); - if (!list_empty(&coredev->buffers)) { - cb = (struct smscore_buffer_t *) coredev->buffers.next; - list_del(&cb->entry); - } + /* This function must return a valid buffer, since the buffer list is + * finite, we check that there is an available buffer, if not, we wait + * until such buffer become available. + */ + + prepare_to_wait(&coredev->buffer_mng_waitq, &wait, TASK_INTERRUPTIBLE); + + if (list_empty(&coredev->buffers)) + schedule(); + + finish_wait(&coredev->buffer_mng_waitq, &wait); + + cb = (struct smscore_buffer_t *) coredev->buffers.next; + list_del(&cb->entry); spin_unlock_irqrestore(&coredev->bufferslock, flags); @@ -1127,8 +1147,8 @@ EXPORT_SYMBOL_GPL(smscore_getbuffer); * */ void smscore_putbuffer(struct smscore_device_t *coredev, - struct smscore_buffer_t *cb) -{ + struct smscore_buffer_t *cb) { + wake_up_interruptible(&coredev->buffer_mng_waitq); list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock); } EXPORT_SYMBOL_GPL(smscore_putbuffer);