From patchwork Thu May 23 20:29:17 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: 10958761 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 00C8F15A6 for ; Thu, 23 May 2019 20:30:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D37142869B for ; Thu, 23 May 2019 20:30:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C74CA28767; Thu, 23 May 2019 20:30:20 +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 B44E02869B for ; Thu, 23 May 2019 20:30:19 +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 443E31607; Thu, 23 May 2019 22:29:27 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 443E31607 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1558643417; bh=G3zoIUAvqk/5JF65hqIwqMykw3i60NaTMPLMGnlwbM4=; h=Date:From:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=M1HjBFp3oOkuLdGH1eSU0V6JYEyeegGqW34VckfP3YCm5+xyCuDt0XjnNqj0bSFq/ pKQUjct8DjMDAqb5nE2Xui297EKmT2auXjZzATq4mR8d1q8yoiqdneCbbqCzp3Vs9l WSNsGe3kM0e3tzf57AeMQ9MQwI7SVzOTA43P24fo= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id C5350F89670; Thu, 23 May 2019 22:29:26 +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 39677F80C0F; Thu, 23 May 2019 22:29:24 +0200 (CEST) Received: from gateway30.websitewelcome.com (gateway30.websitewelcome.com [192.185.144.21]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 68009F80C0F for ; Thu, 23 May 2019 22:29:20 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 68009F80C0F Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 487287030 for ; Thu, 23 May 2019 15:29:19 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id TuL0hx0w24FKpTuL1hJMQd; Thu, 23 May 2019 15:29:19 -0500 X-Authority-Reason: nr=8 Received: from [189.250.47.159] (port=34524 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1hTuL0-000Lzk-50; Thu, 23 May 2019 15:29:18 -0500 Date: Thu, 23 May 2019 15:29:17 -0500 From: "Gustavo A. R. Silva" To: Jaroslav Kysela , Takashi Iwai Message-ID: <20190523202917.GA12595@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: 1hTuL0-000Lzk-50 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.47.159]:34524 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 3 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] ALSA: 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 rate_priv) + src_format->channels * sizeof(struct rate_channel) with: struct_size(data, channels, src_format->channels) This code was detected with the help of Coccinelle. Signed-off-by: Gustavo A. R. Silva --- sound/core/oss/rate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/core/oss/rate.c b/sound/core/oss/rate.c index 2fa9299a440d..7cd09cef6961 100644 --- a/sound/core/oss/rate.c +++ b/sound/core/oss/rate.c @@ -323,8 +323,8 @@ int snd_pcm_plugin_build_rate(struct snd_pcm_substream *plug, err = snd_pcm_plugin_build(plug, "rate conversion", src_format, dst_format, - sizeof(struct rate_priv) + - src_format->channels * sizeof(struct rate_channel), + struct_size(data, channels, + src_format->channels), &plugin); if (err < 0) return err;