From patchwork Wed Feb 28 20:41:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13575928 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D00915E5DD; Wed, 28 Feb 2024 20:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153386; cv=none; b=tI9w45675iuATpmJW7Cn16uKal7ZdmNR2+YEkyzNyD4F5fBNU9cheL9aMmU4cVF9NyxFR09VVafurXp0vpEsh3sHR8DUz9KAeVH4Che6gw+0SLTNaoKjXKjGmwqMfaRUlSzYvVb4i5MdK6+MQ2/RawDeqAI9m4r7pzoBDVoKprQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153386; c=relaxed/simple; bh=E3/6TZHqz4QzVouyFU4/0yUH2cIdu7rmw3fp5xSFDhI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j4kCB5nZBkKCeDWqG2aMuiFQdYhYfcbcImtoIgK4p+ChHBdwH9MMy0WYOxNnCSGOTh69dykdmxJkOuNyUTqnpjCOTSq/Egd4q5Y14UkMddgvFnZ0T8WGaw8sIxOjhHmVlFF5V1Od99eaisro+uCOSabw1u98arVXlGq1ZqyhMSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=XyqdnPOP; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XyqdnPOP" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709153385; x=1740689385; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E3/6TZHqz4QzVouyFU4/0yUH2cIdu7rmw3fp5xSFDhI=; b=XyqdnPOPTr+1yiY8sg4u81oaK4a85KqOgMyO/fe225KNkHqdBoqotuQa olsBOSF86OKAzGipD6PW9j7kCVzNcfSxbOzpNFXOZI2fF136Zh32t3P0P X1lf76/TI89OxoXzXy0756W15rLINNL9W5ewIS+ZaZKmTlZvAWoFRGMXt yNIyhmvuqLCKR7+/7uRL1QTuRIV2pljxVXAcJxnjeiaaw2qV/9t5kWXyx NPPrgyW+yCIrbnv0xmsLQh7IEWMatB4jiFIdxUyppCGqFhXoKMvc+YEBK e0hJ8wwzsBUhwg5GCGhL9+LugBbpZX+Y5c4rv+0J10iD0PFeKhCsHF3E3 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3428721" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="3428721" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 12:49:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="937034660" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="937034660" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 28 Feb 2024 12:49:35 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 0BAAD192; Wed, 28 Feb 2024 22:49:34 +0200 (EET) From: Andy Shevchenko To: Vinod Koul , Linus Walleij , Jonathan Cameron , Andy Shevchenko , Mark Brown , Kees Cook , linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-spi@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" Subject: [PATCH v4 1/8] overflow: Use POD in check_shl_overflow() Date: Wed, 28 Feb 2024 22:41:31 +0200 Message-ID: <20240228204919.3680786-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> References: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The check_shl_overflow() uses u64 type that is defined in types.h. Instead of including that header, just switch to use POD type directly. Signed-off-by: Andy Shevchenko Acked-by: Kees Cook --- include/linux/overflow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/overflow.h b/include/linux/overflow.h index dede374832c9..bc390f026128 100644 --- a/include/linux/overflow.h +++ b/include/linux/overflow.h @@ -197,7 +197,7 @@ static inline bool __must_check __must_check_overflow(bool overflow) typeof(a) _a = a; \ typeof(s) _s = s; \ typeof(d) _d = d; \ - u64 _a_full = _a; \ + unsigned long long _a_full = _a; \ unsigned int _to_shift = \ is_non_negative(_s) && _s < 8 * sizeof(*d) ? _s : 0; \ *_d = (_a_full << _to_shift); \ From patchwork Wed Feb 28 20:41:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13575925 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F272B73509; Wed, 28 Feb 2024 20:49:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153384; cv=none; b=HFPYCaFoD4epYujifYltNridZL7HCSBOJsLKv4E19HIvnU8BtXot4HL//A8Ym2udkzHBvHyPOI6RKCyh6Die0zQDrQPjuDAQSIOq5tJbGiAPI4hIKuUIkHNz7dePMaPtJ0yPEthTGdUny/W8/qzYxZkkHgepQb4y/JcfqdWj/oM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153384; c=relaxed/simple; bh=5rz+s7/pr5Tr5G4CC4rkjs7MtaG8CkV7L7yDYm59sps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e6v6fCKwrhwRR49m848Oj8CLKSFq76dDpSppXxujxotu7XKyQYRbIh+39XOQim2h8Kiehk87e6noZLTyNn3CH+HQdf57hcXY+OeIdbYovKsWglB+pfXsNRp5kvjEm+F/mNbTAYrU2A9xoQcTkpsscqPzmlftLBZWPRkS2wpplws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WHpRlOAk; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WHpRlOAk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709153383; x=1740689383; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5rz+s7/pr5Tr5G4CC4rkjs7MtaG8CkV7L7yDYm59sps=; b=WHpRlOAkmDNw4JVId5nTg1YIaJ/7ucRNRfetXS9EOwurotohsS2OAG3e pHXcwLAX2ul5NMMkbH+5ijjodJPgLcSbD9r0KM5VkAuFcdBJtItM0jlLw Loh9WP/UK/+PTo2OVQff4U5kyD35wX4deyB2RC3vJg7QWM0FUOUhCkak2 6u98T5GAEsusbX185qJAUJ7Fd09ha5lQbwfLEZO2fbRpOjsUe8iUU9L0w WUkkTnid0P/qrkUtI5X66eExoCLyiK2nwDjQg93qTspnGaokSRjzQpMtx lv/9miu7qEPI0y+kzepwfHAu9nMMPKdah4G3EhhzXs9Z3mdfgCpnHpIdQ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3428690" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="3428690" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 12:49:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="937034656" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="937034656" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 28 Feb 2024 12:49:35 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 1D9D5284; Wed, 28 Feb 2024 22:49:34 +0200 (EET) From: Andy Shevchenko To: Vinod Koul , Linus Walleij , Jonathan Cameron , Andy Shevchenko , Mark Brown , Kees Cook , linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-spi@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" Subject: [PATCH v4 2/8] overflow: Add struct_size_with_data() and struct_data_pointer() helpers Date: Wed, 28 Feb 2024 22:41:32 +0200 Message-ID: <20240228204919.3680786-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> References: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Introduce two helper macros to calculate the size of the structure with trailing aligned data and to retrieve the pointer to that data. Signed-off-by: Andy Shevchenko --- include/linux/overflow.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/include/linux/overflow.h b/include/linux/overflow.h index bc390f026128..b93bbf1b6aaa 100644 --- a/include/linux/overflow.h +++ b/include/linux/overflow.h @@ -2,9 +2,10 @@ #ifndef __LINUX_OVERFLOW_H #define __LINUX_OVERFLOW_H +#include #include -#include #include +#include /* * We need to compute the minimum and maximum values representable in a given @@ -337,6 +338,30 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend) */ #define array3_size(a, b, c) size_mul(size_mul(a, b), c) +/** + * struct_size_with_data() - Calculate size of structure with trailing aligned data. + * @p: Pointer to the structure. + * @a: Alignment in bytes before trailing data. + * @s: Data size in bytes (must not be 0). + * + * Calculates size of memory needed for structure of @p followed by an + * aligned data of size @s. + * + * Return: number of bytes needed or SIZE_MAX on overflow. + */ +#define struct_size_with_data(p, a, s) size_add(ALIGN(sizeof(*(p)), (a)), (s)) + +/** + * struct_data_pointer - Calculate offset of the trailing data reserved with + * struct_size_with_data(). + * @p: Pointer to the structure. + * @a: Alignment in bytes before trailing data. + * + * Return: offset in bytes to the trailing data reserved with + * struct_size_with_data(). + */ +#define struct_data_pointer(p, a) PTR_ALIGN((void *)((p) + 1), (a)) + /** * flex_array_size() - Calculate size of a flexible array member * within an enclosing structure. From patchwork Wed Feb 28 20:41:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13575927 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5875C15E5B7; Wed, 28 Feb 2024 20:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153386; cv=none; b=o2fzdI8b5HG0g8nKKjEYeaTAQDb4qsjbRT+/bAGHLZ7QQNhV6mwA9y31rD5uvXMMem0YyN5gabXLradhf1bCjxzv/NpsfGDhEwUOBPzrnjXVTnss4CXwGIEyIf7ZMCxWwBQGsDQGFKBI4OaWvKIeig+6ccNSy/8Wu06EXlPzZwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153386; c=relaxed/simple; bh=ChX9iCdEwwQPReQLo1Sn+5tF0+KgHD07SNo+rL4s+7A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ghsZa+7D1cxkcT+0cwbcHfyKsaBf1EoW71HpZf+LSXXPEpztErRU+2GP6xHUtjc5yzCeZ7IxYt3SLLvbZ9D1+Z5iX+DY+BVclAx0XKTNn2Jue+TKvHahkukdaWK1WDEDfpu1jhAbZHvV2Hl4m+8x+gutV5KVvrqjabIM4ZpUcNk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Y/ITHgv9; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Y/ITHgv9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709153384; x=1740689384; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ChX9iCdEwwQPReQLo1Sn+5tF0+KgHD07SNo+rL4s+7A=; b=Y/ITHgv9+k2jQzkwooRBH/GkgS0d3ftUaXLpRhwrotAT0zoskDVx7jf9 idC0XvGHvzfPINRwLU+sj8FG3RLc8om2EYUx1uRKdP3vntwVDVoEZ9AVJ c07ZcylbXFX801TRLkobEWFbkskeqTOKXm3bjo5tNwMGNQgBA3GvCBmTB rzqI7zTRswFvYfc5uXf1Zr5ymcqPuSQIlBuTJYcvb0ADoK/QMBc62UvL6 Qd2OV5TsnqaipdT4+9yHrn898YqQTQiiM8wBC1BdBXQiTreS0INVIMcvN EOSl3bf9JZglh5JgGafIU/iJVlqdiGqmUDJdlqgYqd5G3V10/RMk68AZH A==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3428719" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="3428719" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 12:49:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="937034658" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="937034658" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 28 Feb 2024 12:49:35 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 2E89B426; Wed, 28 Feb 2024 22:49:34 +0200 (EET) From: Andy Shevchenko To: Vinod Koul , Linus Walleij , Jonathan Cameron , Andy Shevchenko , Mark Brown , Kees Cook , linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-spi@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" Subject: [PATCH v4 3/8] iio: core: NULLify private pointer when there is no private data Date: Wed, 28 Feb 2024 22:41:33 +0200 Message-ID: <20240228204919.3680786-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> References: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In iio_device_alloc() when size of the private data is 0, the private pointer is calculated to behind the valid data. NULLify it for good. Fixes: 6d4ebd565d15 ("iio: core: wrap IIO device into an iio_dev_opaque object") Signed-off-by: Andy Shevchenko --- drivers/iio/industrialio-core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 4302093b92c7..bd305fa87093 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1654,8 +1654,12 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv) return NULL; indio_dev = &iio_dev_opaque->indio_dev; - indio_dev->priv = (char *)iio_dev_opaque + - ALIGN(sizeof(struct iio_dev_opaque), IIO_DMA_MINALIGN); + + if (sizeof_priv) + indio_dev->priv = (char *)iio_dev_opaque + + ALIGN(sizeof(struct iio_dev_opaque), IIO_DMA_MINALIGN); + else + indio_dev->priv = NULL; indio_dev->dev.parent = parent; indio_dev->dev.type = &iio_device_type; From patchwork Wed Feb 28 20:41:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13575924 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EEF7571ECC; Wed, 28 Feb 2024 20:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153383; cv=none; b=m8LSTPq2wBCb7SoxzMBdwHmD4HKdIRMRgjnUljy+EllwmqCQxmYpFEczQ6dPAB8lyLo9Tjsuv5Vu/CToM8NT4KALhZxGdMavdQPhrXDgN5hYI4m7neyJUoww9E2LxjEFeIt/gcMb7UWcdDawxa67/+PuFdmaRBAO4B2zLOZ1qoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153383; c=relaxed/simple; bh=bSX7yIwX43d/OsXwr5kkmyf++rin8N4VYe4LXrJgvRQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZfKuravMgxafUKTyd1bSNrP7z9CSkQKTfapA3lpVUzW/BS6a5rFcvRwX3NSSpSUrnkbXL6Cn55zjbEHbdOST9st7yM37fMflg64HOWytexJ6YEFrij6IrVaXPP2FM3qwKJNp4KPYgM04gbCUlYekSgRS4yOpPX/WtMxToJ7UJIU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=meZNFtV5; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="meZNFtV5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709153382; x=1740689382; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bSX7yIwX43d/OsXwr5kkmyf++rin8N4VYe4LXrJgvRQ=; b=meZNFtV5g+j2wCZ08yPnnZHrTFvEiDWp9jjC61JRCsnEULFXkiNEavbI 9jqeyrq5Rk3jXXyXTLchwtDQ815eC6XDhpnM17zuX7pic5EjWRmD+SHI8 mEkfkJExm+OrXeiIzWEpVd/88roMLXerSGV8nGK06kt6Eb1pPf/OIL4Co PbGBZv+/5zIzpp3dunlKn1tvARMViE7499Ehu1YqftNnQGlSrPnr/YKmI YldSbMsb6LS+SjwrZty8giyYaQ+g6MJp7kplrA6aj9zfPCjR4KryQdAJZ Pxxu5KCkJ4H6NZ71jUX1CeNRCTkPfHrTrr9FMS6HJX/7qw1iii/XCiJ31 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3428674" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="3428674" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 12:49:40 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="937034659" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="937034659" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 28 Feb 2024 12:49:35 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3AD28524; Wed, 28 Feb 2024 22:49:34 +0200 (EET) From: Andy Shevchenko To: Vinod Koul , Linus Walleij , Jonathan Cameron , Andy Shevchenko , Mark Brown , Kees Cook , linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-spi@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" Subject: [PATCH v4 4/8] iio: core: Calculate alloc_size only once in iio_device_alloc() Date: Wed, 28 Feb 2024 22:41:34 +0200 Message-ID: <20240228204919.3680786-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> References: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 No need to rewrite the value, instead use 'else' branch. This will also help further refactoring the code later on. Signed-off-by: Andy Shevchenko --- drivers/iio/industrialio-core.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index bd305fa87093..1986b3386307 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1643,11 +1643,10 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv) struct iio_dev *indio_dev; size_t alloc_size; - alloc_size = sizeof(struct iio_dev_opaque); - if (sizeof_priv) { - alloc_size = ALIGN(alloc_size, IIO_DMA_MINALIGN); - alloc_size += sizeof_priv; - } + if (sizeof_priv) + alloc_size = ALIGN(alloc_size, IIO_DMA_MINALIGN) + sizeof_priv; + else + alloc_size = sizeof(struct iio_dev_opaque); iio_dev_opaque = kzalloc(alloc_size, GFP_KERNEL); if (!iio_dev_opaque) From patchwork Wed Feb 28 20:41:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13575932 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED8A17290F; Wed, 28 Feb 2024 20:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153389; cv=none; b=rhP3ApDz/Ut0GxEWgtkJTe3fF/aZ992W+SYgqpgLgDDDg2AAs0dV27FiLS7DlKpFaUjnpaf6PSqDmyM2YlPEVhuEJWAZuXUNdmhfM2Q+pweWhy+qb3IW9OB+lE4sO2tebiU18hy1YQQtFXKWmDun4agWA48TmbOJ7D6D0Tx3MAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153389; c=relaxed/simple; bh=R9j+Q0D/kA76h1U7UfPAGebwhkhuz8MuAm681KRIxuM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pwd96xwLoNVNWozv/agsIctPrz9W6rsbSGv9lgeu2evaJvuBJCNdhVjx9K+7KZvgtpz67g+JOujc97Tg88wfAVIN0lem4kaBj9sXYkLKFvurFzQRAxRSMsqG+yfEmX6vV0G/7hZFJsE1OuuzHixBfbe7VkJgWwvLcNi8XbXRegg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=lzvgQX7d; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lzvgQX7d" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709153388; x=1740689388; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=R9j+Q0D/kA76h1U7UfPAGebwhkhuz8MuAm681KRIxuM=; b=lzvgQX7dZu4f6YrJlOMYTKNoU18zl/LQvhBde5z6BP4SO+LBslH0Fvbf pL4rbYBwVqNPOZ2JlK3pIQIPJxStuQU8OxlKiZtJMooZUYnUQjHmnKS5R E5eMdUm8JMnfhDPGwZUpnJ6KX3UVosgLsfnJsvX20pCNneksEQiVIvrAi uhGqLQ+7q6H4zVBdJMDevYpIDSqYhIWIL6yj3QUWYFNSdRF5zR+oNyI9J 1f58ogcsphCl5RI/q1XoMm7KKUWLPTM1SyEG1/wg2o6+3ndrfm+tbcTDh Zbq5Ykk5mqZZSd8S+O5TSysmz/aFpsyWhBxMLubj59+ptIGc4EPeb1Qkp A==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3428774" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="3428774" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 12:49:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="937034662" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="937034662" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 28 Feb 2024 12:49:41 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 47C0A537; Wed, 28 Feb 2024 22:49:34 +0200 (EET) From: Andy Shevchenko To: Vinod Koul , Linus Walleij , Jonathan Cameron , Andy Shevchenko , Mark Brown , Kees Cook , linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-spi@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" , Nuno Sa Subject: [PATCH v4 5/8] iio: core: Use new helpers from overflow.h in iio_device_alloc() Date: Wed, 28 Feb 2024 22:41:35 +0200 Message-ID: <20240228204919.3680786-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> References: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We have two new helpers struct_size_with_data() and struct_data_pointer() that we can utilize in iio_device_alloc(). Do it so. Signed-off-by: Andy Shevchenko Reviewed-by: Nuno Sa --- drivers/iio/industrialio-core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 1986b3386307..223013725e32 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1644,7 +1644,7 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv) size_t alloc_size; if (sizeof_priv) - alloc_size = ALIGN(alloc_size, IIO_DMA_MINALIGN) + sizeof_priv; + alloc_size = struct_size_with_data(iio_dev_opaque, IIO_DMA_MINALIGN, sizeof_priv); else alloc_size = sizeof(struct iio_dev_opaque); @@ -1655,8 +1655,7 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv) indio_dev = &iio_dev_opaque->indio_dev; if (sizeof_priv) - indio_dev->priv = (char *)iio_dev_opaque + - ALIGN(sizeof(struct iio_dev_opaque), IIO_DMA_MINALIGN); + indio_dev->priv = struct_data_pointer(iio_dev_opaque, IIO_DMA_MINALIGN); else indio_dev->priv = NULL; From patchwork Wed Feb 28 20:41:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13575929 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0F75C161B5E; Wed, 28 Feb 2024 20:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153387; cv=none; b=ji1YIzy2udDDd5L7hUBEfHPX1xUtVP2x5oFI5hZ6HPM9wn2ASvL9/CapDb5a0OmIqKgDEjquK7mLWqYCnUF3QeKy+KAyZe/JG4PLRXvibf8oEtzMvJOXga9NcAoYoMnnKKfyJ1VRtabO08pF0QIa4hDuAy+Mpq9qcaFGMAFNCXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153387; c=relaxed/simple; bh=fln8BdnmbmK5Zmrs6qz4ah5cZtVSbnFVhGrQ/3X00RA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bR7qa05MAhi3G2dw3jxnruL91zj34tLoh58VHmIAKBJrGhvh2EQtvof3OqaVptcXBPXO5LPN0AdpHqLkX0Z/eZOWXuJbhSvVzvii6WmGQQdLnjm1p3/qmsp/bBn653AjNVhQvAuwDMQZbNoguFylNgIrFCKFFxvA7CnQC2RC2/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=UTuIpcQ2; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="UTuIpcQ2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709153386; x=1740689386; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fln8BdnmbmK5Zmrs6qz4ah5cZtVSbnFVhGrQ/3X00RA=; b=UTuIpcQ230LmuxNDCIdadBUqS+tHM90i9tt8na+4IkYKQFw3HtqNRfz2 jmsoUS3mKEwHsG66ovYl59pC2pD2HT3ajEpNvx7ZJyiNGOE5keefIplPX IQoAOlsvMejxbTM3APXI9YYRNMjK3z8JHSPnX4eI84zfJst/1qiPxzoB0 L0LYz7yVyvtqYPOBHmubs6pZ8U/ECJ4VcDhJtmYJ6cHsqrSjrYWv6p0wM fpY3cR/sOlB0v8J5WTmLzCZ0bIBSneWOF70MC0DT6LHI81IiUZNIrzc1H mEm/nh9Isvt1rxRBxzgAPBE+efrR3ZMWoY/elnag/+mak+Bdx4cM6THK2 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3428740" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="3428740" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 12:49:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="937034661" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="937034661" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 28 Feb 2024 12:49:41 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 538665F5; Wed, 28 Feb 2024 22:49:34 +0200 (EET) From: Andy Shevchenko To: Vinod Koul , Linus Walleij , Jonathan Cameron , Andy Shevchenko , Mark Brown , Kees Cook , linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-spi@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" Subject: [PATCH v4 6/8] spi: Use new helpers from overflow.h in __spi_alloc_controller() Date: Wed, 28 Feb 2024 22:41:36 +0200 Message-ID: <20240228204919.3680786-7-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> References: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We have two new helpers struct_size_with_data() and struct_data_pointer() that we can utilize in __spi_alloc_controller(). Do it so. Signed-off-by: Andy Shevchenko Acked-by: Mark Brown --- drivers/spi/spi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index ba4d3fde2054..de7a23da58c6 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -3089,12 +3089,12 @@ struct spi_controller *__spi_alloc_controller(struct device *dev, unsigned int size, bool slave) { struct spi_controller *ctlr; - size_t ctlr_size = ALIGN(sizeof(*ctlr), dma_get_cache_alignment()); + int align = dma_get_cache_alignment(); if (!dev) return NULL; - ctlr = kzalloc(size + ctlr_size, GFP_KERNEL); + ctlr = kzalloc(struct_size_with_data(ctlr, align, size), GFP_KERNEL); if (!ctlr) return NULL; @@ -3114,7 +3114,7 @@ struct spi_controller *__spi_alloc_controller(struct device *dev, ctlr->dev.class = &spi_master_class; ctlr->dev.parent = dev; pm_suspend_ignore_children(&ctlr->dev, true); - spi_controller_set_devdata(ctlr, (void *)ctlr + ctlr_size); + spi_controller_set_devdata(ctlr, struct_data_pointer(ctlr, align)); return ctlr; } From patchwork Wed Feb 28 20:41:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13575931 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E9BD70043; Wed, 28 Feb 2024 20:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153389; cv=none; b=rLt5856WQuBj8mieEEjC43sLL244EwMtjO1Wx4B4+zHO5h29rCNQ8dVjJq6xVWuV2yGHevkYyd+miykkLWRb+xbUWeJ6XnHZHVmWenKjYtBIsC9uku3q4KFFfsBqJb39bR8UhBjDmrKkUKdrX/P6Ch7xXiYtiB4teQYeh/zfKlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153389; c=relaxed/simple; bh=F4b2geX9W5KhXMqEu52b1/d3qPI5zOp6cxLtiYLUnNE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SqnoIAWR5oJNPkQss2PxqD+CUoxEOce/LfejPiVyWmVzORnozwPwlYOEY+3Byfg8NANbcMN6D2Isf6Lf+JbKxGjWQ2S1RM6fPGHiWjbaYgDUNpfjG3ElsB8g4GB69Y6E9vkJUl8eufVGP1KYfTVJmXs/2YjwVFptJvm6gFs9W6g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=F/gkgw7Y; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="F/gkgw7Y" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709153387; x=1740689387; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F4b2geX9W5KhXMqEu52b1/d3qPI5zOp6cxLtiYLUnNE=; b=F/gkgw7YM9B+7loM2W0xpqJ6jU57HuXvleaDALSY3xUIkht9c2Uqq2if 1aCwAGj6DK5nwW7qgwzqB/VqHjhle1XB9yMxqu3/x0eiADWoVNNu3rTpm sqoeXt2/sj8R2OYBn27EIOl0d0F4FRN4FPoIAzAPHYac+E89ShrkltgIU qsOAujLc7sR2VoDzzr82BeHQTz/SyFzcQ/lP+G4RAYwNP7P4w7NKvp/bO 4mmqY/mOZWHCxcaXViIKhC7OrKpdGUGCmoYE+V2Yy6ofYV+v+DyXCBKDF cQ8fJYmxhMjhrrUIzP1S5rmCy1JB/eiFzFT0FbhCv7wz0DJ7XGyPzEN2Y g==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3428771" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="3428771" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 12:49:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="937034664" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="937034664" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 28 Feb 2024 12:49:41 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 5F749631; Wed, 28 Feb 2024 22:49:34 +0200 (EET) From: Andy Shevchenko To: Vinod Koul , Linus Walleij , Jonathan Cameron , Andy Shevchenko , Mark Brown , Kees Cook , linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-spi@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" Subject: [PATCH v4 7/8] net-device: Use new helpers from overflow.h in netdevice APIs Date: Wed, 28 Feb 2024 22:41:37 +0200 Message-ID: <20240228204919.3680786-8-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> References: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We have two new helpers struct_size_with_data() and struct_data_pointer() that we can utilize in alloc_netdev_mqs() and netdev_priv(). Do it so. Signed-off-by: Andy Shevchenko --- include/linux/netdevice.h | 3 ++- net/core/dev.c | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index c41019f34179..d046dca18854 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -2668,7 +2669,7 @@ void dev_net_set(struct net_device *dev, struct net *net) */ static inline void *netdev_priv(const struct net_device *dev) { - return (char *)dev + ALIGN(sizeof(struct net_device), NETDEV_ALIGN); + return struct_data_pointer(dev, NETDEV_ALIGN); } /* Set the sysfs physical device reference for the network logical device diff --git a/net/core/dev.c b/net/core/dev.c index 69c3e3613372..80b765bb8ba2 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -10859,12 +10859,12 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, return NULL; } - alloc_size = sizeof(struct net_device); - if (sizeof_priv) { + if (sizeof_priv) /* ensure 32-byte alignment of private area */ - alloc_size = ALIGN(alloc_size, NETDEV_ALIGN); - alloc_size += sizeof_priv; - } + alloc_size = struct_size_with_data(p, NETDEV_ALIGN, sizeof_priv); + else + alloc_size = sizeof(struct net_device); + /* ensure 32-byte alignment of whole construct */ alloc_size += NETDEV_ALIGN - 1; From patchwork Wed Feb 28 20:41:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13575930 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5DA470024; Wed, 28 Feb 2024 20:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153388; cv=none; b=A4I/YGhh7YB2UJXVAYotwg7A2QWygpwDT/3YxWzznFJxoGlJTzk1rk7VQTn6jSEBn1PQ7i3IujN8kgJMAmOrVbK+2DOpFUkZXvHxY61AN0jsIfIncCuBK2hCagQ03+GwjOxHYvfJwS5jRekYlh6wNSNnlPp9KSOjNWljKTJjaK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709153388; c=relaxed/simple; bh=8BAIf0j7CaHKQ/zZDl1HE0ybcnT2/U9McrHMACFS6nk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bc6m38LBgqBZkBhVaFOtO+WM5p2QxZ8o3FtlkQCeA2ForQLLRsS5mqXmZ150IPNqqpksrdFB/R+ifzRjCAEA//Yy1dPEbUlmF6xqymY1Xm30Tw+mcCVVNjBgaLK2K9Xn2yI8cYM2vPR4HbHSKdrMxPw65FDIbK2NzIda08I08Bk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QZ09pxQo; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QZ09pxQo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709153387; x=1740689387; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8BAIf0j7CaHKQ/zZDl1HE0ybcnT2/U9McrHMACFS6nk=; b=QZ09pxQorS2cktz5/PqzrEEJ1ZhQzKXIsb/o28M2LCQ+Y/WAQrWPi0VI Rnv6d9HOpXGy6XYOgXfU6x6TWSfN5oVmL2F8YxXIUAyYmk8CjoMPkjzsW Fwn1wxZlojqJnEXm59296i/tLew/BkQND+BmXAjUhUQ84Y98vJiDMKV7t KEqO3hTKBM7agMu1DmK4Y9H+bai+gkmYnYO8A6rAZ11lZXv8mTFqS9Y7L qWIeOqx9ig/8Igy/UlXUQ2WnbV+GN033+kopYAGurPJQzxiccqpA/OwJz +IHR+BErf/HlrfaSP/wON9gSqHMrs9buO8WTXEFpX6SwySuDkVhDZfHdo Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3428753" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="3428753" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Feb 2024 12:49:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="937034663" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="937034663" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 28 Feb 2024 12:49:41 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 6F964715; Wed, 28 Feb 2024 22:49:34 +0200 (EET) From: Andy Shevchenko To: Vinod Koul , Linus Walleij , Jonathan Cameron , Andy Shevchenko , Mark Brown , Kees Cook , linux-arm-kernel@lists.infradead.org, dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, linux-spi@vger.kernel.org, netdev@vger.kernel.org, linux-hardening@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" Subject: [PATCH v4 8/8] dmaengine: ste_dma40: Use new helpers from overflow.h Date: Wed, 28 Feb 2024 22:41:38 +0200 Message-ID: <20240228204919.3680786-9-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> References: <20240228204919.3680786-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: dmaengine@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We have two new helpers struct_size_with_data() and struct_data_pointer() that we can utilize in d40_hw_detect_init(). Do it so. Signed-off-by: Andy Shevchenko Reviewed-by: Linus Walleij --- drivers/dma/ste_dma40.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c index 2c489299148e..bead3b8836c7 100644 --- a/drivers/dma/ste_dma40.c +++ b/drivers/dma/ste_dma40.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -3141,6 +3142,7 @@ static int __init d40_hw_detect_init(struct platform_device *pdev, int num_log_chans; int num_phy_chans; int num_memcpy_chans; + size_t sz; int i; u32 pid; u32 cid; @@ -3207,11 +3209,9 @@ static int __init d40_hw_detect_init(struct platform_device *pdev, "hardware rev: %d with %d physical and %d logical channels\n", rev, num_phy_chans, num_log_chans); - base = devm_kzalloc(dev, - ALIGN(sizeof(struct d40_base), 4) + - (num_phy_chans + num_log_chans + num_memcpy_chans) * - sizeof(struct d40_chan), GFP_KERNEL); - + sz = array_size(num_phy_chans + num_log_chans + num_memcpy_chans, + sizeof(struct d40_chan)); + base = devm_kzalloc(dev, struct_size_with_data(base, 4, sz), GFP_KERNEL); if (!base) return -ENOMEM; @@ -3223,7 +3223,7 @@ static int __init d40_hw_detect_init(struct platform_device *pdev, base->virtbase = virtbase; base->plat_data = plat_data; base->dev = dev; - base->phy_chans = ((void *)base) + ALIGN(sizeof(struct d40_base), 4); + base->phy_chans = struct_data_pointer(base, 4); base->log_chans = &base->phy_chans[num_phy_chans]; if (base->plat_data->num_of_phy_chans == 14) {