From patchwork Wed Jun 15 12:15:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Sakamoto X-Patchwork-Id: 12882256 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 6A927C43334 for ; Wed, 15 Jun 2022 12:17:07 +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 6551F18E8; Wed, 15 Jun 2022 14:16:15 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 6551F18E8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1655295425; bh=XX+Aa+fT1RjwyoHoUXPHFjHKmen0LBK6YIBMddLOd4s=; h=From:To:Subject:Date:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=s7Mspsz4YkzrSGWiR+JyoX6h8kyDlpMfeH8OwtgtpAc4Jiu7OrfU5v6mAIsUqFyAp UW0uM+9yW/F5AP+kMy4j4McAOcSM3GkqFKWNaZpDLZRzdmnjfOqr2JNYaM7RCJ1emo vrulsqFMc9RpnUkrZ5fOiL0Lmi3i0NiMVh/yfO6s= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id C079EF80527; Wed, 15 Jun 2022 14:15:28 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 9EE80F801F7; Wed, 15 Jun 2022 14:15:26 +0200 (CEST) Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 68D19F800B9 for ; Wed, 15 Jun 2022 14:15:18 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 68D19F800B9 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.b="pOgL8x/L"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="PVvL8wis" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id A0E5D320094C; Wed, 15 Jun 2022 08:15:16 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 15 Jun 2022 08:15:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-transfer-encoding:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm2; t=1655295316; x= 1655381716; bh=MtKBc2bhfjgMYC9HTZUX2V0/dMYlGGjy+AYAPIY7ZaY=; b=p OgL8x/LCbQn1ZNkAoeJT4yLKckCmZt8L9inva/gKLl6CpoP9eEI22A/mBzZX9jnm wqyNxQVfZtkidxjFf8VlyecFpGPQ09/gslVQ5d70YOwlFecNNKsLrTqLySQIjwhL aSx7iJ2RcepelsJ6cf+ZX5C6uHPLVViDbMUCDlGZy1fYbElhRJWB3vIiGHUjzU/c u92UHw8GtvDbS1QFCC8N/ZV5p71LYSX0EMla5a3am/2HjWFlp2BnbaseFbsN1Tqv 6HFt8YnkA54eCI8cLcnghCsLv6D6EGIZyFTLFC+PSum3ZQkQge3ndIeLeMZuJZJx ZEzDhF4eVqN01DYLFN3Xw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1655295316; x=1655381716; bh=MtKBc2bhfjgMY C9HTZUX2V0/dMYlGGjy+AYAPIY7ZaY=; b=PVvL8wis2OyJPIAnu6qZutU3QqpUW RtyTWLXpnh6h7PzT0oEq45F+GGr3AMHs0YPPblpfJuxT1o4o33wMMrI7iF7YqmOn huXzEkzdumAHvu34ciSbfvcnwqwwEvMBfXFPB2dVbSde0i+OdxP50ctK3/LlhG2R XLTk6qh85FV+sQ4cGUSfu/DjZpP28hXLrw40c8daTnhHXGKovUakyrVJlyidGfQA mQZeuiKt7CRdkT3M1IHPnZusupUxYy+841Pd/Tw3+kjOOJ05z4Fmrwv4QCtIil1e NWwWh7Js6UJoA5rIh+Sm7fywjqmiI3JhngJQTyUrMPY7bmIC4fG9FFyyg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedruddvuddggeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomhepvfgrkhgr shhhihcuufgrkhgrmhhothhouceoohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhird hjpheqnecuggftrfgrthhtvghrnhepvdejgfejuedvgfduudekleevtefgtdevhfdtffef iefgveeuteffiedvffekvddtnecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpe hmrghilhhfrhhomhepohdqthgrkhgrshhhihesshgrkhgrmhhotggthhhirdhjph X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Jun 2022 08:15:14 -0400 (EDT) From: Takashi Sakamoto To: tiwai@suse.de, stefanr@s5r6.in-berlin.de Subject: [PATCH v2 2/3] firewire: use struct_size over open coded arithmetic Date: Wed, 15 Jun 2022 21:15:04 +0900 Message-Id: <20220615121505.61412-3-o-takashi@sakamocchi.jp> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220615121505.61412-1-o-takashi@sakamocchi.jp> References: <20220615121505.61412-1-o-takashi@sakamocchi.jp> MIME-Version: 1.0 Cc: alsa-devel@alsa-project.org, linux1394-devel@lists.sourceforge.net, "Minghao Chi \(CGEL ZTE\)" 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" From: "Minghao Chi (CGEL ZTE)" Replace zero-length array with flexible-array member and make use of the struct_size() helper in kmalloc(). For example: struct fw_request { ... u32 data[]; } Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes. (Revised by Takashi Sakamoto to fix the value of third argument.) Signed-off-by: Minghao Chi (CGEL ZTE) Signed-off-by: Takashi Sakamoto --- drivers/firewire/core-transaction.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c index af498d767702..4604a9d97fd1 100644 --- a/drivers/firewire/core-transaction.c +++ b/drivers/firewire/core-transaction.c @@ -779,7 +779,8 @@ static struct fw_request *allocate_request(struct fw_card *card, return NULL; } - request = kmalloc(sizeof(*request) + length, GFP_ATOMIC); + request = kmalloc(struct_size(request, data, length / sizeof(request->data[0])), + GFP_ATOMIC); if (request == NULL) return NULL;