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: 208074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a1a:b0:17b:cd04:e0c6 with SMTP id 26csp260226rwa; Wed, 28 Feb 2024 15:40:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX/oJ45S7PniCVl1h71AmRb3JjcalnSDlVd+RirZsE04pjuCMAEj9ieS0WwiuDY/Ut85NbbH1vx47V8WQRmouwFVgHS+Q== X-Google-Smtp-Source: AGHT+IFy8y5XLyDsvu5M74yzQtmWTWTrzn0tXVkXXpK05R/ifMGmVDVDxrBzN4nim8o64Ssy38f+ X-Received: by 2002:a05:6214:162c:b0:68f:6279:eb04 with SMTP id e12-20020a056214162c00b0068f6279eb04mr535682qvw.24.1709163624850; Wed, 28 Feb 2024 15:40:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709163624; cv=pass; d=google.com; s=arc-20160816; b=MXtJN9Kla/ERN9SyoW2hL+2ZuOiTue7XBV2FUEp6ehplJ7CXDeB750f0tf+4J5+vYs HGCvVvW4rqH/d2SFpG/WkFVp9Q3OF8VT2CuIG9SaQIxihSR0U128Ev1X3buh8tthWF2j L/y5/4ETVZNhYqB2P/m9dnrCEvyYwgKHIq1iQqdYPNJWsg+OjWobaXLcvrnUJkffqcJv ABKLRM0SRiBzPEq0tB7iCMTORsbO0V7h27z9XWv7A+R2oBVvCPV7suGUmq59BnI20vsM SijXYdta3s0umMszduya2khYRlLM2F9bwQn86vNJv0t34lhUI2QXQQip6Z4GXm7LpWMI g5eQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=XUCnKt27yp3L+3p8A9jePeqpe31IgTXOaqPws6Ekqiw=; fh=SDJEwBjUOHB9dr3Xf35E782n6oCWBirh57Q+2DGhRIA=; b=u6hmsJM3tiy5ZNTv+OZnnbyQ1bigClPYDTaKlPNrb3JFZs/C+dduIM4cEEdnYnxH7U F8AhDnEJfreF8xixKXiGdAhXB1imT5jqwAZq9/xstN1KDzdmT+bdpGr26VhCIcw1rCMy xu/so6i5aaXiJ5OF1Aa+aDbyFgHjAoHvmrsBfTcgo7RQOsmsH6orpu3Hp2qHzzRIiij5 l/JJJx3cBHSs9bo7K1+urAowpGM8gM64R1vDL+dfHTB+qERLYoQJyYc5fQRTu2JpaosN gvSJEVyuSWGDc2zDNOMGPzFxsyck3a2ceR5Rr4tEdkun3W44stzBBsG6YvfgJtUqIjub 6xIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XyqdnPOP; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85691-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85691-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id od8-20020a0562142f0800b0068f07fbcbffsi208732qvb.43.2024.02.28.15.40.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 15:40:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85691-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XyqdnPOP; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85691-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85691-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8BD191C26E70 for ; Wed, 28 Feb 2024 20:51:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9251473509; Wed, 28 Feb 2024 20:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XyqdnPOP" 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 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792179983439360296 X-GMAIL-MSGID: 1792187956728572783 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 --- 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: 208194 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp160310dyb; Wed, 28 Feb 2024 19:56:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUxVPAeP0ebAxjta1vvJb2rPfgwh5b5/D/UdKZJGzsr33zo25pl140cNdYnHYGc4A+4nvPuMczISXlrwFzVIu9sdrZuVw== X-Google-Smtp-Source: AGHT+IE5KuR/NJ9QsZWVI/NfKuFM+AUeJivQIZt8O+srJOWTv7YSAeMVB01iB6kLaiiu3zjEs3/w X-Received: by 2002:a17:906:c28e:b0:a3f:b7cb:cc52 with SMTP id r14-20020a170906c28e00b00a3fb7cbcc52mr484614ejz.40.1709179007816; Wed, 28 Feb 2024 19:56:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709179007; cv=pass; d=google.com; s=arc-20160816; b=p++rkWdtLeWQ8DHIsrqrOptECExkMyMpOBubMW4oKqHaZL8kLhNXlIRLamXJxcZM7Q 0vcsYsDsajm23cp8v57V3Yyrb77zVtOawnYBjmb0xQ/sPzCGDkZpmDSQ5iaRROAlAEo6 lkZTuf0vUsoWXDN4sKDpV4XiQnBlkMeIKHBXtPFk5AFHMDjVyH8HO6lqkEvM4MEwmrQM zMqkYnWp1Z36I6/yd68d5DF8lJQrYomUH+Be9k/6bzzyuu7kTvDu3E1p9H7UG5wq+1Re ZqKNEm9Z/Be/6TIVg+ZDi36gi8eRMWOUIvPZ6X5gigvUen79uPNgyn7EhmGeW/W9PE/O FIAg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fRhjGPCSqYe3aNilCAmuS0t4962KPYn9rI4qvYbIPWM=; fh=SDJEwBjUOHB9dr3Xf35E782n6oCWBirh57Q+2DGhRIA=; b=ZTUwDYzoGH4lqmnS9GhrNFtEt8cuJOnubE39/eHUoebJPE229tUUcATW8ME4fnJPVz EwF1mb85gva38Xjc8Ax82xvBh9HqwPaWrft2+qEuX4GJrj9MABS6mTYcf+WCiC1LBWt6 72GqF30713q0H9AjzBbnjDdrHTa0ZF9w5jwEc35wQnlrTeGnEp0zxPH0QjGROqdjrAMe DRwvovisZnNQ5AI3mA1IVR5vIhbzXS2YBFsE78vMeyGO+AqpLRqPvjbJMqxlomeD7pEJ ZPEy5nZJ0eYDdaD3Cqy7iNXstq0jtwjqpqXbTCn+O9zwc8exFRfaJiCDMRrFVWf/7nr2 EkrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WHpRlOAk; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85688-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85688-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id mf26-20020a170906cb9a00b00a4411a11400si201063ejb.559.2024.02.28.19.56.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 19:56:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85688-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=WHpRlOAk; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85688-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85688-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CBAA31F29F1D for ; Wed, 28 Feb 2024 20:51:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C3C5C15DBB5; Wed, 28 Feb 2024 20:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WHpRlOAk" 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 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792180266268814895 X-GMAIL-MSGID: 1792204087218504580 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: 208166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp132852dyb; Wed, 28 Feb 2024 18:24:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWTuW7NFpQjB3+lSbFIbFvOwqxFWQI8LoECIEoeuIECfFoRPzKhUB7OtmaiDiJxWsAV6jSNdC6jyY0fHogSmGHJEXyUQQ== X-Google-Smtp-Source: AGHT+IFBXwVs2umjrkFJD/AKdhkiUTkplnAkLeeoiSqdzFbFuy7GoY1UZgUy5M4XRX4IiJHe9NZw X-Received: by 2002:a05:6808:1a08:b0:3c1:ae84:a37e with SMTP id bk8-20020a0568081a0800b003c1ae84a37emr918821oib.56.1709173480245; Wed, 28 Feb 2024 18:24:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709173480; cv=pass; d=google.com; s=arc-20160816; b=d6FfXMCtiuy3LmqUGZy/+KOftbGAhgU+5bg2DhLiMAqcjsgTez/KROHsn4M/cpYSh6 mkKOomrCyvVAt8Oor0SIURufvL7QzZQtkkVxY6vzcOrFQUuk2ASX6nzFGEcrwAy42E6x X6YWbusuRFyUtqRoMa2EBqwmx+5grKFq2MKI0ARUJBVuNKCCuYzCsOXzROdeNc28Gar+ AlZvNjw7/1V6ens9UdfuAbp1b7muM8n1MA7tbaCWYTdn4SmJ1xZtpRLYKvKYAWree1+B VKWFfzPqz6vWIcbcyC/DW/txT1YAcLvo5zpbi01MFsos0jHquGNdtKkvYRDkC7g/jTYf t8hA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=j1gEtItvKrEcU8Ne6gFZc64YL9qCYI7qGhDGeQxOW7o=; fh=SDJEwBjUOHB9dr3Xf35E782n6oCWBirh57Q+2DGhRIA=; b=qETbpvPBLVJSavrWs9/w0Md4ZyLHSCI4zrwLxuzAP2hEdPHn+kXlZugrTwur9Qt1fJ ZkD+8ZCFmSF4WXU9MnsEsbd2nRL5O6mz6kLMTRfhQqO698prwK9GrVFPHcwcphb58Zri JsWWqVs4Wmr2RVx4J6YCkGROzmT6m0w0AQ2tzm2ikb45CSCdaxeQefSDX2vqezzzWtfM VoIHKKodKfuC6NgFZ5/KgBbcE9FveiwD1QHl55eAY794bgFfddoLZwAkxIaLJWMnsNBs QozgXve2d6dv8/3uHXFc0n6uXcab9WI8rI9+SGrXS9qKul7zjSwp5JJ7CHQAjbF4Ohvi pcmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Y/ITHgv9"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85690-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85690-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id f2-20020a056a000b0200b006e4ecc281adsi321904pfu.105.2024.02.28.18.24.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 18:24:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85690-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="Y/ITHgv9"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85690-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85690-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 817BAB23990 for ; Wed, 28 Feb 2024 20:51:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1AEA76EF0; Wed, 28 Feb 2024 20:49:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Y/ITHgv9" 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 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792179388526071589 X-GMAIL-MSGID: 1792198291308034251 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: 208062 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a1a:b0:17b:cd04:e0c6 with SMTP id 26csp231970rwa; Wed, 28 Feb 2024 14:30:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVtcOSDWKinBV3A1yKxqZEyEblwdypzjqxUClAqB623JHPfP/ErMeMPPqF/8jLYqpOJZx2Di4uF3jhcBGDFMVRDcgNdnQ== X-Google-Smtp-Source: AGHT+IGtedQoCWHxqCvWEWmSAtJnpOixxy92Yv/DZoWH6VCf0ZM1VORMov9pZCW5UtbmW7iiIKnE X-Received: by 2002:a05:620a:621c:b0:787:caf2:e1b1 with SMTP id ou28-20020a05620a621c00b00787caf2e1b1mr409640qkn.51.1709159421260; Wed, 28 Feb 2024 14:30:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709159421; cv=pass; d=google.com; s=arc-20160816; b=GTSOws41kszdQWJFYIe7+nPVK8fNBhU58kxjZZe6KI64lyZ3uTnAkuf9Fy/ml6OsT9 oin69HzQwTCc8+CjNtCWoxyM0HUyOh1szZtkFR63c2avqvfbHlyp0/Pv5kpG87+orxoQ 2Q7OKuWMr8Yk8e5hQgC4taRaSE2BTfrRdofWwlu63P2xCIWyK9tWy0X8k11vLoD9IlsM 1aaXs5w2MK4JJR5HbMgENv096OmgbJUyhbONCEhkPxnrt80LsowiAUfNHDp1JwIUg5Cb e0PCZlgMMSroVEIQYNaA0tggiKATYDXUpFWrAYSQ66JvinWoQ7zzEEsP06DuGAcE1b6c LpCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=In2F4CcBTcy4RqfaLJ0KEkRlRxTiV+hdqV94xLLXIOk=; fh=SDJEwBjUOHB9dr3Xf35E782n6oCWBirh57Q+2DGhRIA=; b=AfLdj+2qcyhqZ4qQ15Q0MUM8SbYwqbB3D1jERLnSKuhgT86FUcwRO5pbNela9p4Dui U4sY0mleigVAvwYeNNEjoK7EYsapJq63MRkWTSXQKHsUMuWoHXN9QRK4ol8nA712H1o/ mMpsgl5gmMDiYei5V6AdY/RDiGXsgUEceOLQALL7uV+27GPFcDWCyuEuJH2TmFOwSeFK 3/NycHUmXnYuNJHWQi/l6l6fMCCntNVnOrKNChEOnGiEbcYKtcrO071FnLBBa9O6WyeW E0its6sdWaabRbP8OsV6BY8d8fkQyI2XDJr8RIpIOUrNQfZkcDOiEwz3daIUoAdC9Zsb KmHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=meZNFtV5; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85687-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85687-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x8-20020ae9e648000000b00787f8cbb7e9si125872qkl.669.2024.02.28.14.30.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 14:30:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85687-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=meZNFtV5; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85687-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85687-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2018E1C266B9 for ; Wed, 28 Feb 2024 20:50:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64B481649D0; Wed, 28 Feb 2024 20:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="meZNFtV5" 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 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792178742304413394 X-GMAIL-MSGID: 1792183549429296358 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: 208118 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp100134dyb; Wed, 28 Feb 2024 16:51:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXtdv7VBbpx8s/ucdNnB6eUToWoxkW+OQPy8BZSm7pYIkNOSMqedDl+KOUtIjP1y2aZsMuiwD6CVOnEYTzK9acrOt4boA== X-Google-Smtp-Source: AGHT+IH5OzalICUfXLJKMDNKwgaLUFXxBpPsVJVmR8lvMeAZhemMx3TzseZSbR/yd8hhd7n/no59 X-Received: by 2002:a17:90a:8a0a:b0:299:5a55:ef3a with SMTP id w10-20020a17090a8a0a00b002995a55ef3amr884672pjn.4.1709167869575; Wed, 28 Feb 2024 16:51:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709167869; cv=pass; d=google.com; s=arc-20160816; b=Q9FHr6GP9JQi2neYy3T+R5Js7Qt+YpqVGgMf0ZiNo2xmkV4O94I3jvTNSQUe7/WIik BE0dbcEr2d/pw3W3gC+didMikHRwrI97VxM0C24ojLoGIuCIp3g3ht2VauTb2XRAocfu FXn0aDAvSKfUeTtjWPhxfQ0As6+BOK+5cw/sRjnSN2hNXHORbCo/4rBOjmSiCCBeEZSJ E/kT9DgDVQbvhwqVAGL6KVcfbLYaciuZtLERQNsJvb1dhXW/s+SaE1OEgZ5CynCKus9r i0ThM6UyJi0nHIHwFQQS11C10Z8wZOjxfHZ/Ll+MAR2DWkodll2NI94Vr517Yy8az64T tTRw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=9VI+tzy9q3a5cGA3aUoO+hv/XHY7hHOuGFLHfSDNihs=; fh=bBcueXoyYQ/4owtJ51rB6UqpyJY1f++Rn9/MV1CTR2g=; b=BFptpXU3oIDgOHkxJ5BPDd6paHP/7CiqTRrm97DsCPkVRys+UangU0NYt+3dnu1+0Y +WA6BgTNOo0Mv+3yyhNmqwN4EG88ti8HB6sWiV4U+zF0shJlsDjGHIN+N2WTIuDf7A3m JERxoCOSWqTKhygRR0J6S96K9pPXjoZtFkbdeCuDsqwmZNFmA5lgA109/in7F+0gS3EE PPFlbbuHH+L4lUOFEZdUj5b3MMlUiVWclyKxO0sPffXWR5H9PnU5TYo83tT64OqIA0yS +DDAcIBEuKeIoeR50ndbt3NucNrVxt28jpwUS6zMgWzkNORboiwbqQ1KDjAzJb+NzDlk e3Ng==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lzvgQX7d; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85695-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85695-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ot18-20020a17090b3b5200b0029b0f0e85acsi118021pjb.9.2024.02.28.16.51.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 16:51:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85695-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lzvgQX7d; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85695-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85695-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B5A8A28D670 for ; Wed, 28 Feb 2024 20:52:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 636AF86262; Wed, 28 Feb 2024 20:49:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lzvgQX7d" 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 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792192408391210382 X-GMAIL-MSGID: 1792192408391210382 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: 208053 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a1a:b0:17b:cd04:e0c6 with SMTP id 26csp223815rwa; Wed, 28 Feb 2024 14:11:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXVB2mKp1y2kVhcRnEKbHz3HKOhSGM+/9uOvsTscshnmMxzLk2l+xMRuFVMTWpptEn+D1kGDR40pxrYLlx7uBHnyLNqKw== X-Google-Smtp-Source: AGHT+IGjJwYFi86F7ypvSAy4ftg9EUx2BPcHXuFO24cSnI6E+zvjNoFfFwGdadOAds3hqmsHzfWF X-Received: by 2002:ac2:4829:0:b0:513:226c:6489 with SMTP id 9-20020ac24829000000b00513226c6489mr140005lft.69.1709158304361; Wed, 28 Feb 2024 14:11:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709158304; cv=pass; d=google.com; s=arc-20160816; b=wcapu+M0+8wwZ39QD5MVVI+aXjScOeHWwcycOM3B5Y2fHKZG1pcGVmdkXs7z5R7kIh faPoXLjotK8WnWPvCzRluOtyVAdlyr7nswX/6yFXTdXsrkBB+oM3LUeXvSfEOLYhaZea ly51wDqrCrXLNY2gUkvvLBzs9HgiLjgcM7BBdGDQGicwENOSP5BZCy4rN34O3jgjBEef TAUhiFg12jr578tqR/J0DkB5TmlZ5PVaLt28Ejb75i+cEAfmm3RC7nNXtYk3UO4xMPzF uSoBG0rwT9LggS5+BkiM0sm+tTCAjE4aQ6I3oZI+QVFQOGLQzbVvlVCxYcpbg3Vx2TzY heyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Qwjj6EN8zjX4RhLl91o/H/XNh4Xfrho6yCZnRfKib68=; fh=SDJEwBjUOHB9dr3Xf35E782n6oCWBirh57Q+2DGhRIA=; b=TvHN5pFj/pg6glJr/VS3fD4xA36xv/d5ifJ5r3/a6rJaIJa49ix6fC5qUsi+zjcJS3 s5PNf95vXy17loqjs1X/5JkyauZiRhZPhBdQsj8aiGVuylOn2EHD2ZD0UcVQXuYJ5V3h t03Cw5rr807eBQYjPQPIdkFbzXjwi1mPOhquM6MAjaOEYGh259Yc7zvVPbWSMMW4S0Ks CNcaW9p/6KaIioJw6ffZWMg6ozRY5PLzNCHyHBfjawitAb43QTwqMauvROChvwGmvrph PCoiVYOUowv3v7mWmtQjf7UPaA9rSBPb8POHnit3936VfiYO5jOzKFkIktD4vUviLI77 jffA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UTuIpcQ2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85692-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85692-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u16-20020a170906409000b00a3f180e5da6si2077810ejj.273.2024.02.28.14.11.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 14:11:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85692-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UTuIpcQ2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85692-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85692-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D104D1F2ABD5 for ; Wed, 28 Feb 2024 20:52:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9AEFA7D098; Wed, 28 Feb 2024 20:49:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="UTuIpcQ2" 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 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792177913618794638 X-GMAIL-MSGID: 1792182378143877363 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 --- 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: 208063 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a1a:b0:17b:cd04:e0c6 with SMTP id 26csp240851rwa; Wed, 28 Feb 2024 14:53:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUWzddA602QS5gLF0waMhOTqjUjQgJFIhfAZsHIfMDR+pr16AiK76ePTaQjTr36xrU2KDH2MUU571I/Mhd9lGQHrwBGZQ== X-Google-Smtp-Source: AGHT+IH/vHMvky40JiJgbZsgGYEuKeiTBGswdUOfxX8H9HsXO425zktUvDLh0O0+kEcExN+Tlf+m X-Received: by 2002:a9d:7acb:0:b0:6e4:ab08:26f1 with SMTP id m11-20020a9d7acb000000b006e4ab0826f1mr348950otn.7.1709160817955; Wed, 28 Feb 2024 14:53:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709160817; cv=pass; d=google.com; s=arc-20160816; b=PsL7JGwkLyjvWpgKgJidUJMx1m58DLExRn8D99H+iAmHX41Nk9DR0okZwbEw4/Iv5a UczGxl6+nVNxfJ2a2lSlqXQGv4KEOSOFlet3rXtgQfs1realLABz96CVGZngenrKrtNG 9GIhXWvCn8r7iBSeMVIiURGo5YPWtivosdeKrwNS+9XZh2+Rs4+3hNzkcIxHG/yF7JMb zH3ks7rwRt9QGQNbIRgZ2f9Y0lVhqY7f9YLKeihRZo1CBZaWPNGR3cuJcF+qAthCM/M5 LtCzy9xYRcEvwEHQsHYXaWFrIHr9OsH7chqC5zcsyXXpPBeKRHtd1JHyN0jKkUMliOSS 6rBw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=VoOuNpVbp12gb0UNvqB1OvHcbWGCnuTG1v0q+w1cJfs=; fh=SDJEwBjUOHB9dr3Xf35E782n6oCWBirh57Q+2DGhRIA=; b=ekZMvhL7koMGHxEy+ZYDw2Sitifb1IXfksXpWPUYA4CfwmUeEc3WfBY4SB3+/3Fehn f+mkrxVo49KLw3V0TAcfYm6nDPlCpMX3gJ1rjp2sVJkw8iHnssy8ei1WzX+taplDVztj 2Vyeo5HkEIkxebcEBygmUguG7LbAF/Psut224NBwgEHO03+DOQba8qJ/CW1AoQvFtD/+ 2WiQJLtHH7aUF7DAXRW26bDFBSKCQLrt8hFzWa2hWUn8oaTn+pfSHhTNJZQ2YD/tiPpS fgKzQBMBDhIExQA+cxL/DG8BhdXUXdw0jcpJ+68VPb3HFjF6V+UVZUsILQfNGMcLLhTr 7I6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="F/gkgw7Y"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85694-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85694-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h6-20020a635306000000b005d8505c96e1si31209pgb.423.2024.02.28.14.53.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 14:53:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85694-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="F/gkgw7Y"; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85694-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85694-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4B32FB21598 for ; Wed, 28 Feb 2024 20:52:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C731686258; Wed, 28 Feb 2024 20:49:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="F/gkgw7Y" 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 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792181253983750251 X-GMAIL-MSGID: 1792185013851484260 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: 208052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:a1a:b0:17b:cd04:e0c6 with SMTP id 26csp223176rwa; Wed, 28 Feb 2024 14:10:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUWnekBO/SByAKkK0T0MVFp9XQmpyVtLZ6bFobEKT+WktdJbNoHqvzR7Vzm9GgBTjmSTL41UMVlsaDfoI71ZZBZcFWs3A== X-Google-Smtp-Source: AGHT+IHUDnDaSP2A/VHLtlXJciqPC4SBqUcv2qsaKSdiKmvOEqTTLyoAIlNr9gBI5ewRa6rqZeHB X-Received: by 2002:a05:6870:f6a5:b0:21e:f03b:8836 with SMTP id el37-20020a056870f6a500b0021ef03b8836mr203345oab.52.1709158228155; Wed, 28 Feb 2024 14:10:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709158228; cv=pass; d=google.com; s=arc-20160816; b=FruNGT55D0VJQzyDwmmpPabP6sr5QjQ5Ta39xF5xdGQHVFdlregK7i8NKxiSzBIvM+ CnDhRw4vV+gjNOCsKTAHMKTYF1fegLHN1CddVtN0L3va+1I4pjmIh3Sp1qsxBZOnRr4k VlX4gnmbx7dd1GB/ljXUrgKQDxzmMtDr6AwMa75QgT2kFNY+TSBKtpOumfJ4Iox8uO0Z luqIk41GtXIQGLV8qqkn0wEzmWIloN9XZwASLsY3g4GL3f3ej9vsu0HH74YYkO8T2JqH uZBgupovB2s4jgF6R9oQyQVGIbPIzGmhBRTeAY4495W38YHnVORCZhXJnlBAWpIqZ8l3 P+og== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=fQMfBhc1n6DTIzVjiwqqIpnk4wi4d2GCnJ4A/mgp6Sc=; fh=SDJEwBjUOHB9dr3Xf35E782n6oCWBirh57Q+2DGhRIA=; b=q+x/sdflzUtSeWu30FYIgoQd+M1HyHngmHLURYOMG7NxeblsxFFHiBCOJ8HNv9h0au gAVWEIoHFcnS5170zJlB2YDxY2U+MduZREOy4lJs3bUjQlu1wOvdxdDBgMaaW0f4G7mf AoEmVZiB4yywHhYkfFVqe+cTs525vPG/PR2pnBIAZxkQQ853vSdC2NsxM9vDzANmc0OT vMy3VZsd1U8hSPbLUsUG7qvT5nFJfq4/vZuIH7AP+EJDgS1+FWwq3t5GWaPOMZkg5LXh NT+Y7xQZuGRBystywOSMx8nrRBzAK48uvIMUuTjCXKxiGA0ESqmw5sDhIfjzxLn6vWuT E8UA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QZ09pxQo; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85693-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85693-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p5-20020a05620a22a500b007878dd1aed6si109672qkh.71.2024.02.28.14.10.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 14:10:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85693-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=QZ09pxQo; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-85693-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85693-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 273241C27150 for ; Wed, 28 Feb 2024 20:52:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47B668624A; Wed, 28 Feb 2024 20:49:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QZ09pxQo" 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 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: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792182298466420969 X-GMAIL-MSGID: 1792182298466420969 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) {