From patchwork Tue May 18 13:00:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 441269 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9136EC433B4 for ; Tue, 18 May 2021 13:04:19 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B16D96112F for ; Tue, 18 May 2021 13:04:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B16D96112F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 1C1A916FC; Tue, 18 May 2021 15:03:27 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 1C1A916FC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1621343057; bh=4ZthGqZeKTaIjIG5CBCaIAbLmtMGABwrRUrG+YZheWM=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=ud3IzOCWfuXWJ70F3GwoC2+cXx9tk/Jjm9u2To1zaFFmfABGRXG6ZjdrBjMGbkxyu fBESx/Pj861nX6pmCnIktk8dAfgaRUbhr3wqdZR6TSZU8PDRLDjlO5L51mggeAnyq0 /AxMmU/j6q8fYu0N0FOWW+Kd5Dw77D5yNHqPui/Q= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 20897F804AC; Tue, 18 May 2021 15:01:17 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9C3C5F8042F; Tue, 18 May 2021 15:01:11 +0200 (CEST) Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 947BBF80229 for ; Tue, 18 May 2021 15:01:04 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 947BBF80229 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="qbX0Jit4"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="pqmtcYk6" Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id AF2015C0036; Tue, 18 May 2021 09:01:03 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 18 May 2021 09:01:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=KmvqkE0omOlH5 WFCl9vbPkS/ACyDpzuwKRVOiti1Hn0=; b=qbX0Jit48/b1DM3pOaFRyuhXEdbnW 62MyM4L4z/mzoJcqVnDVH42hTCEAYoR+XzTCvqsUYgWa3YxbtsQJUuVObmdpgiZh qROcyrkOFT/k1GFfebVvM6s5qAvsD2+xFpfDdGNxWqH1BlvXuVBmCeCS0HR23GTK eZ71IQCN8l7JolTyTT+qxbrMti0VmEL1CjOY7jMke8jZT0peEj3OPZwNamllO4Sx u0170/Z+RXSXEp99bzwdjRZ6yrTSXJzPK2opaXgrYZDOau91LXj2POI2MWX+2BX4 XfnOVtA3RZleTPv0MR3IXYlBE39sJ7Hi1sbN8LdzuUVJMGECtcQ+LPHSA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=KmvqkE0omOlH5WFCl9vbPkS/ACyDpzuwKRVOiti1Hn0=; b=pqmtcYk6 sqyLwAJ1T0+ZU4af2vI8jkv0nIS0hldW6dXD6lofNyMPgOza1e8DBO5OYr2mvKjm 8Q5OzYoU6E3FLBsyEIbMebWa/9xdvPISLSvNrTGN7N8y+eg4KKLqHsZinge+erNj 42KhaeNMmZykQYouF2zbdiN6eScmP5Noyc/TeKVtVB9+YJ7nDyeEu7Gzx34aM7QS QEkMcbNYbOIwdqtfMDEQyu4vq2snkXUBvQBlRa8PbY9hpoYHjRQuFOHRwIJI4ez1 Xw4oRhc7g0hWPKUBddwuFKmB5K9Xsk1aDmcrN8PaTWG4M7Zy/gHiiJKkUOuUVmJ/ DfjLkfvwjktweQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdeijedgheekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomhepvfgrkhgrshhhihcuufgrkhgrmhhothhouceoohdqthgrkhgr shhhihesshgrkhgrmhhotggthhhirdhjpheqnecuggftrfgrthhtvghrnhepveefffefke etgfevgeefleehfffhueejtdejveethfekveektdejjedvtdejhfejnecukfhppedugedr fedrieehrddujeehnecuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilh hfrhhomhepohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjph X-ME-Proxy: Received: from workstation.flets-east.jp (ae065175.dynamic.ppp.asahi-net.or.jp [14.3.65.175]) by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 18 May 2021 09:01:02 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de Subject: [PATCH 6/8] ALSA: firewire-lib: code refactoring for check of CIP header about payload size Date: Tue, 18 May 2021 22:00:45 +0900 Message-Id: <20210518130048.146596-7-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210518130048.146596-1-o-takashi@sakamocchi.jp> References: <20210518130048.146596-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, clemens@ladisch.de X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" The size of CIP payload is now passed to helper function to parse CIP header. Signed-off-by: Takashi Sakamoto --- sound/firewire/amdtp-stream.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sound/firewire/amdtp-stream.c b/sound/firewire/amdtp-stream.c index 1c530678e56a..1ff25e6b0c78 100644 --- a/sound/firewire/amdtp-stream.c +++ b/sound/firewire/amdtp-stream.c @@ -574,8 +574,7 @@ static int check_cip_header(struct amdtp_stream *s, const __be32 *buf, /* Calculate data blocks */ fdf = (cip_header[1] & CIP_FDF_MASK) >> CIP_FDF_SHIFT; - if (payload_length < sizeof(__be32) * 2 || - (fmt == CIP_FMT_AM && fdf == AMDTP_FDF_NO_DATA)) { + if (payload_length == 0 || (fmt == CIP_FMT_AM && fdf == AMDTP_FDF_NO_DATA)) { *data_blocks = 0; } else { unsigned int data_block_quadlets = @@ -590,8 +589,7 @@ static int check_cip_header(struct amdtp_stream *s, const __be32 *buf, if (s->flags & CIP_WRONG_DBS) data_block_quadlets = s->data_block_quadlets; - *data_blocks = (payload_length / sizeof(__be32) - 2) / - data_block_quadlets; + *data_blocks = payload_length / sizeof(__be32) / data_block_quadlets; } /* Check data block counter continuity */ @@ -658,8 +656,8 @@ static int parse_ir_ctx_header(struct amdtp_stream *s, unsigned int cycle, if (cip_header_size > 0) { if (payload_length >= cip_header_size) { cip_header = ctx_header + 2; - err = check_cip_header(s, cip_header, payload_length, data_blocks, - data_block_counter, syt); + err = check_cip_header(s, cip_header, payload_length - cip_header_size, + data_blocks, data_block_counter, syt); if (err < 0) return err; } else {