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: 701464 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4774BEB64DA for ; Mon, 10 Jul 2023 10:28:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233366AbjGJK2S (ORCPT ); Mon, 10 Jul 2023 06:28:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233369AbjGJK2G (ORCPT ); Mon, 10 Jul 2023 06:28:06 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9B66DF; Mon, 10 Jul 2023 03:28:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1688984884; x=1720520884; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8VTp2VvPftW0K82t/UQGFNBKatn1Y+wh44m0tYwuY/M=; b=g8kHiAPP6TGGFqXvjn72yC75JytBHRgumZGRrrzUhyAvMZZNw5IpkR3Y 8TY+MxqZN0gu8mgzyNIlp8/8dNpi8LqyDyYFoiJ/WhVMA0VxzMAR3/+uZ 8Uetc3yk3jZowfmo1dLQEFKEPFArGoTqWhDqoTBInGfNdCDV2F3xeLOwP jG2bh7URQQSAea3yVp7NEGfS/ex8wba7SlKYuUaOKV8ADz0wMNdADv/uZ CQEvXtytuU96weI8/YeNyaeQdKssZ2xSDVbt1AujmKbyFs/NvmGn2BR0L avcmFtMpSLEuFZiA7rhsZpK1YiQe9QtN+ftuVllq42XRFstf2aY9sq9wf Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10766"; a="367803792" X-IronPort-AV: E=Sophos;i="6.01,194,1684825200"; d="scan'208";a="367803792" 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 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org 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; }