From patchwork Fri May 22 14:00:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 6464731 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 44B6CC0020 for ; Fri, 22 May 2015 14:02:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5B42D20221 for ; Fri, 22 May 2015 14:02:04 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 0350D20483 for ; Fri, 22 May 2015 14:02:03 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id E68D3265FE4; Fri, 22 May 2015 16:02:01 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 7FA4D265D8A; Fri, 22 May 2015 16:01:25 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 30137265D9D; Fri, 22 May 2015 16:01:24 +0200 (CEST) Received: from smtp302.phy.lolipop.jp (smtp302.phy.lolipop.jp [210.157.22.85]) by alsa0.perex.cz (Postfix) with ESMTP id 4865D265B4C for ; Fri, 22 May 2015 16:01:02 +0200 (CEST) Received: from smtp302.phy.lolipop.lan (HELO smtp302.phy.lolipop.jp) (172.17.1.85) (smtp-auth username m12129643-o-takashi, mechanism plain) by smtp302.phy.lolipop.jp (qpsmtpd/0.82) with ESMTPA; Fri, 22 May 2015 23:01:00 +0900 Received: from 127.0.0.1 (127.0.0.1) by smtp302.phy.lolipop.jp (LOLIPOP-Fsecure); Fri, 22 May 2015 23:00:54 +0900 (JST) X-Virus-Status: clean(LOLIPOP-Fsecure) From: Takashi Sakamoto To: clemens@ladisch.de, tiwai@suse.de Date: Fri, 22 May 2015 23:00:53 +0900 Message-Id: <1432303254-4192-5-git-send-email-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1432303254-4192-1-git-send-email-o-takashi@sakamocchi.jp> References: <1432303254-4192-1-git-send-email-o-takashi@sakamocchi.jp> Cc: alsa-devel@alsa-project.org, linux1394-devel@lists.sourceforge.net, ffado-devel@lists.sf.net Subject: [alsa-devel] [PATCH 4/5] ALSA: firewire-lib: set streaming error outside of packetization X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP In previous commit, error handling for incoming packet processing is outside of packetization. This is nice for reading the codes. This commit applies this idea for outgoing packet processing, too. Signed-off-by: Takashi Sakamoto --- sound/firewire/amdtp.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c index c5034e7..5c0e3ce 100644 --- a/sound/firewire/amdtp.c +++ b/sound/firewire/amdtp.c @@ -651,16 +651,13 @@ static inline int queue_in_packet(struct amdtp_stream *s) amdtp_stream_get_max_payload(s), false); } -static void handle_out_packet(struct amdtp_stream *s, unsigned int data_blocks, - unsigned int syt) +static int handle_out_packet(struct amdtp_stream *s, unsigned int data_blocks, + unsigned int syt) { __be32 *buffer; unsigned int payload_length; struct snd_pcm_substream *pcm; - if (s->packet_index < 0) - return; - buffer = s->buffer.packets[s->packet_index].buffer; buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) | (s->data_block_quadlets << AMDTP_DBS_SHIFT) | @@ -680,14 +677,14 @@ static void handle_out_packet(struct amdtp_stream *s, unsigned int data_blocks, s->data_block_counter = (s->data_block_counter + data_blocks) & 0xff; payload_length = 8 + data_blocks * 4 * s->data_block_quadlets; - if (queue_out_packet(s, payload_length, false) < 0) { - s->packet_index = -1; - amdtp_stream_pcm_abort(s); - return; - } + if (queue_out_packet(s, payload_length, false) < 0) + return -EIO; if (pcm) update_pcm_pointers(s, pcm, data_blocks); + + /* No need to return the number of handled data blocks. */ + return 0; } static int handle_in_packet(struct amdtp_stream *s, @@ -799,6 +796,9 @@ static void out_stream_callback(struct fw_iso_context *context, u32 cycle, unsigned int i, syt, packets = header_length / 4; unsigned int data_blocks; + if (s->packet_index < 0) + return; + /* * Compute the cycle of the last queued packet. * (We need only the four lowest bits for the SYT, so we can ignore @@ -810,8 +810,13 @@ static void out_stream_callback(struct fw_iso_context *context, u32 cycle, syt = calculate_syt(s, ++cycle); data_blocks = calculate_data_blocks(s, syt); - handle_out_packet(s, data_blocks, syt); + if (handle_out_packet(s, data_blocks, syt) < 0) { + s->packet_index = -1; + amdtp_stream_pcm_abort(s); + return; + } } + fw_iso_context_queue_flush(s->context); } @@ -825,6 +830,9 @@ static void in_stream_callback(struct fw_iso_context *context, u32 cycle, unsigned int data_blocks; __be32 *buffer, *headers = header; + if (s->packet_index < 0) + return; + /* The number of packets in buffer */ packets = header_length / IN_PACKET_HEADER_SIZE; @@ -832,9 +840,6 @@ static void in_stream_callback(struct fw_iso_context *context, u32 cycle, max_payload_quadlets = amdtp_stream_get_max_payload(s) / 4; for (p = 0; p < packets; p++) { - if (s->packet_index < 0) - break; - buffer = s->buffer.packets[s->packet_index].buffer; /* The number of quadlets in this packet */ @@ -857,7 +862,11 @@ static void in_stream_callback(struct fw_iso_context *context, u32 cycle, /* Process sync slave stream */ if (s->sync_slave && s->sync_slave->callbacked) { syt = be32_to_cpu(buffer[1]) & CIP_SYT_MASK; - handle_out_packet(s->sync_slave, data_blocks, syt); + if (handle_out_packet(s->sync_slave, + data_blocks, syt) < 0) { + s->packet_index = -1; + break; + } } }