From patchwork Mon Jul 10 10:27:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13306755 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 24863EB64D9 for ; Mon, 10 Jul 2023 10:30:50 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 4433C7F4; Mon, 10 Jul 2023 12:29:58 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4433C7F4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1688985048; bh=8VTp2VvPftW0K82t/UQGFNBKatn1Y+wh44m0tYwuY/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=Co9jqsf8/v7QJeyprndhYOGhOM3qQ1w4pAILFKFATGmsIMinfOboU9rylftg6SZTN P/HOVkwUhVbAs7ukRnYBZNWFdtHNYciXymLDvJYwfjhDd6e0tQyq+me1STgucDPPTB Ds9mtXO+AvzXFucdyJw3/7vNoDn7URI2t+icmZzM= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 0F660F805A9; Mon, 10 Jul 2023 12:28:32 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 913F5F805AD; Mon, 10 Jul 2023 12:28:32 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id C16C2F8059F; Mon, 10 Jul 2023 12:28:28 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id A63C0F8047D for ; Mon, 10 Jul 2023 12:28:07 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz A63C0F8047D Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=KV2g6wSd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1688984889; x=1720520889; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8VTp2VvPftW0K82t/UQGFNBKatn1Y+wh44m0tYwuY/M=; b=KV2g6wSdhNgJwrrj/lziNCk7zWWURw1azZVMJvGBCPCVmYFc8H2pPx1a KM3pG/jkBObxXoMEpUN2xsFe3dVITsBF5mk5ob68IXnKAJ0mkTNdRBan2 4lngqwha5P2Aliv3CpJVmeR8gz9YwfTyrW2hqSO0M8wcIbb63tVRYy4rV PUjs9o2+MVEWTNbiDPOmClrrwDEjrK8xNXzzxYr21Y6k1j6+7YWhz77Js W9ZhS0GZyaE/rwpy8xa9oEtb5THAoah5dpsRhjjtDwDD8spSHndzKM3X0 /tRuJiqICU3BZarfm0y+NzJC1+5rnnAr50gLBOaKXwr19z5cZN9ah4JZ9 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10766"; a="367803799" X-IronPort-AV: E=Sophos;i="6.01,194,1684825200"; d="scan'208";a="367803799" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2023 03:28:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10766"; a="755956019" X-IronPort-AV: E=Sophos;i="6.01,194,1684825200"; d="scan'208";a="755956019" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 10 Jul 2023 03:27:55 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 6D8A169F; Mon, 10 Jul 2023 13:27:53 +0300 (EEST) From: Andy Shevchenko To: Mark Brown , Yang Yingliang , Andy Shevchenko , Amit Kumar Mahapatra via Alsa-devel , Kris Bahnsen , Neil Armstrong , Tharun Kumar P , =?utf-8?q?Uwe_Kleine?= =?utf-8?q?-K=C3=B6nig?= , linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, netdev@vger.kernel.org Cc: Radu Pirea , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Tudor Ambarus , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Matthias Brugger , AngeloGioacchino Del Regno , Alain Volmat , Maxime Coquelin , Alexandre Torgue , Max Filippov , Richard Cochran Subject: [PATCH v1 8/8] spi: Use struct_size() helper Date: Mon, 10 Jul 2023 13:27:51 +0300 Message-Id: <20230710102751.83314-9-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230710102751.83314-1-andriy.shevchenko@linux.intel.com> References: <20230710102751.83314-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Message-ID-Hash: EMXB4SCE2KVVKJB6MCYB5POU2A2IYZ2Q X-Message-ID-Hash: EMXB4SCE2KVVKJB6MCYB5POU2A2IYZ2Q X-MailFrom: andriy.shevchenko@linux.intel.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Prefer struct_size() over open-coded versions. Signed-off-by: Andy Shevchenko --- include/linux/spi/spi.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index e9fb96016dc1..d4d686af76bd 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -1100,6 +1101,8 @@ struct spi_transfer { * @state: for use by whichever driver currently owns the message * @resources: for resource management when the SPI message is processed * @prepared: spi_prepare_message was called for the this message + * @t: for use with spi_message_alloc() when memory has message and transfers + * together * * A @spi_message is used to execute an atomic sequence of data transfers, * each represented by a struct spi_transfer. The sequence is "atomic" @@ -1154,6 +1157,9 @@ struct spi_message { /* List of spi_res resources when the SPI message is processed */ struct list_head resources; + + /* For embedding transfers into the memory of the message */ + struct spi_transfer t[]; }; static inline void spi_message_init_no_memset(struct spi_message *m) @@ -1214,16 +1220,13 @@ static inline struct spi_message *spi_message_alloc(unsigned ntrans, gfp_t flags { struct spi_message *m; - m = kzalloc(sizeof(struct spi_message) - + ntrans * sizeof(struct spi_transfer), - flags); + m = kzalloc(struct_size(m, t, ntrans), flags); if (m) { unsigned i; - struct spi_transfer *t = (struct spi_transfer *)(m + 1); spi_message_init_no_memset(m); - for (i = 0; i < ntrans; i++, t++) - spi_message_add_tail(t, m); + for (i = 0; i < ntrans; i++) + spi_message_add_tail(&m->t[i], m); } return m; }