From patchwork Fri May 24 16:10:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 10960085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 214DE1390 for ; Fri, 24 May 2019 16:12:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EC0E28830 for ; Fri, 24 May 2019 16:12:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 024D228776; Fri, 24 May 2019 16:12:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D2E6D28830 for ; Fri, 24 May 2019 16:11:59 +0000 (UTC) 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 6353E1724; Fri, 24 May 2019 18:11:07 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6353E1724 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1558714317; bh=Pbpb75kbZdiY/D7w2nQhJwvhGFLj5sun7xvOTyHakSk=; h=Date:From:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=NrKXBrtodPZwMKYJN6j9Gp697GFI/uhKmP74mW7HbXEH4bshxx+3aPKJmIf8g9brW RfXup+fVmVqGiPzaenGnpvuAKeiDMjZZdHrU7fNRhRO1Bgu056MpPx7IbJME+Mx64E L5qd1duc7fUrEFImtYSF1/wAH3DfxZRhwOm7EzgM= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id DF59AF8962F; Fri, 24 May 2019 18:11:06 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4AF3CF89630; Fri, 24 May 2019 18:11:04 +0200 (CEST) Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.146.87]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 5E831F806F7 for ; Fri, 24 May 2019 18:10:57 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 5E831F806F7 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway33.websitewelcome.com (Postfix) with ESMTP id 1EE2CB4FA38 for ; Fri, 24 May 2019 11:10:56 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id UCmVhnggGYTGMUCmVho5LS; Fri, 24 May 2019 11:10:56 -0500 X-Authority-Reason: nr=8 Received: from [189.250.47.159] (port=47748 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1hUCmS-001c1Z-RV; Fri, 24 May 2019 11:10:55 -0500 Date: Fri, 24 May 2019 11:10:51 -0500 From: "Gustavo A. R. Silva" To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai Message-ID: <20190524161051.GA26061@embeddedor> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - alsa-project.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.47.159 X-Source-L: No X-Exim-ID: 1hUCmS-001c1Z-RV X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.47.159]:47748 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 5 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [alsa-devel] [PATCH] ASoC: SOF: topology: Use struct_size() helper 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" X-Virus-Scanned: ClamAV using ClamSMTP Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used. So, replace the following form: sizeof(struct sof_ipc_ctrl_data) + sizeof(struct sof_ipc_ctrl_value_chan) * le32_to_cpu(mc->num_channels) with: struct_size(scontrol->control_data, chanv, le32_to_cpu(mc->num_channels)) and so on... This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva --- sound/soc/sof/topology.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index c88afa872a58..745cb875863c 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -442,9 +442,8 @@ static int sof_control_load_volume(struct snd_soc_component *scomp, return -EINVAL; /* init the volume get/put data */ - scontrol->size = sizeof(struct sof_ipc_ctrl_data) + - sizeof(struct sof_ipc_ctrl_value_chan) * - le32_to_cpu(mc->num_channels); + scontrol->size = struct_size(scontrol->control_data, chanv, + le32_to_cpu(mc->num_channels)); scontrol->control_data = kzalloc(scontrol->size, GFP_KERNEL); if (!scontrol->control_data) return -ENOMEM; @@ -501,9 +500,8 @@ static int sof_control_load_enum(struct snd_soc_component *scomp, return -EINVAL; /* init the enum get/put data */ - scontrol->size = sizeof(struct sof_ipc_ctrl_data) + - sizeof(struct sof_ipc_ctrl_value_chan) * - le32_to_cpu(ec->num_channels); + scontrol->size = struct_size(scontrol->control_data, chanv, + le32_to_cpu(ec->num_channels)); scontrol->control_data = kzalloc(scontrol->size, GFP_KERNEL); if (!scontrol->control_data) return -ENOMEM;