From mboxrd@z Thu Jan 1 00:00:00 1970 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=-15.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS 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 BC77CC433DF for ; Thu, 30 Jul 2020 14:57:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E15A2070B for ; Thu, 30 Jul 2020 14:57:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729477AbgG3O5x (ORCPT ); Thu, 30 Jul 2020 10:57:53 -0400 Received: from mx2.suse.de ([195.135.220.15]:35668 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726275AbgG3O5x (ORCPT ); Thu, 30 Jul 2020 10:57:53 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id CC8C3ACA0; Thu, 30 Jul 2020 14:58:03 +0000 (UTC) Date: Thu, 30 Jul 2020 16:57:51 +0200 Message-ID: From: Takashi Iwai To: "Gustavo A. R. Silva" Cc: "Gustavo A. R. Silva" , Jaroslav Kysela , Takashi Iwai , alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] ALSA: vmaster: Use flex_array_size() helper in memcpy() In-Reply-To: <96ea053c-f4c9-56dd-0d44-b627b067405f@embeddedor.com> References: <20200729221829.GA10623@embeddedor> <96ea053c-f4c9-56dd-0d44-b627b067405f@embeddedor.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 30 Jul 2020 15:12:33 +0200, Gustavo A. R. Silva wrote: > > > > On 7/30/20 03:41, Takashi Iwai wrote: > > On Thu, 30 Jul 2020 00:18:29 +0200, > > Gustavo A. R. Silva wrote: > >> > >> Make use of the flex_array_size() helper to calculate the size of a > >> flexible array member within an enclosing structure. > >> > >> This helper offers defense-in-depth against potential integer overflows > >> and makes it explicitly clear that we are dealing with a flexible array > >> member. > >> > >> Signed-off-by: Gustavo A. R. Silva > >> --- > >> sound/core/vmaster.c | 3 ++- > >> 1 file changed, 2 insertions(+), 1 deletion(-) > >> > >> diff --git a/sound/core/vmaster.c b/sound/core/vmaster.c > >> index ab36f9898711..21ce4082cb5f 100644 > >> --- a/sound/core/vmaster.c > >> +++ b/sound/core/vmaster.c > >> @@ -262,7 +262,8 @@ int _snd_ctl_add_follower(struct snd_kcontrol *master, > >> return -ENOMEM; > >> srec->kctl = follower; > >> srec->follower = *follower; > >> - memcpy(srec->follower.vd, follower->vd, follower->count * sizeof(*follower->vd)); > >> + memcpy(srec->follower.vd, follower->vd, flex_array_size(srec, follower.vd, > >> + srec->follower.count)); > > > > Changing from follower->count to srec->follower.count isn't obvious, > > so it should have been mentioned in the log; other than that, the code > > change looks good. > > > > Yeah; you're right. I'll include that in the changelog text. OK, then I'll wait for the v2 for merging. > > But since the API isn't in Linus tree yet, I'll postpone the merge > > until the API reaches to upstream. Maybe I can merge this during RC1 > > merge window, as those are trivial. > > > > The API is already in mainline, see: > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/overflow.h#n320 Ah, thanks, I didn't expect that the API change comes after rc1 into mainline. Then I can merge later the commits based on the late rc. Takashi