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: 13575960 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88528C47DD9 for ; Wed, 28 Feb 2024 20:49:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=E9lVM+n7HYNUt+cVMsJ54GPRYdGloMhSsnWi66PdqOY=; b=r47Ogp9f9qOBKF JsAoxAuAztgX9YHW2Nk68lpDT+Qxy2GkfZQMt21j63ThzXitqX0WMRQcAreWkP0Y1JA5bfqoe6XQn x7jenlawfyylj3SZLVicnAh0RtI4Jb4/OHr7XgAfW0tBGpwqLejOc/wl2H/GnLIU98+e8NNjMES85 t+qCBOjpeyWWeoNvOpLT5QTnbRHda2LAs68g6VCcWZcUhAcOGw+q2qTaCqbKCGs45Qt1lWVwrpHN1 IrIOiegUmkgFXrZegWi6EHUJeE15zI5XDzK9DpmGtAtYPN+2BKud3/Bg6qzwQErg7m1htABmIsIyo Pa/Lx7m3FHJ7ZqV8NDjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfQs3-0000000At7t-2GHS; Wed, 28 Feb 2024 20:49:43 +0000 Received: from mgamail.intel.com ([192.198.163.17]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rfQs1-0000000At6v-2jB7 for linux-arm-kernel@lists.infradead.org; Wed, 28 Feb 2024 20:49:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709153381; x=1740689381; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bSX7yIwX43d/OsXwr5kkmyf++rin8N4VYe4LXrJgvRQ=; b=EU9/LrcrGLaF1BrQ4u6C8v7/7YFRx74SGjOO6fXbHYjketooNjKinB36 Ginm/GxNE3zfVf39om7/T01pnEjRqvovW7FmfQvwFOGsm41TDq8tJj59K LvhFI+GcQQnh01pLjBMaVoudYBFaWeiynW2GAELzK5ZUgses3iAK5QW3X TpGKjeA4R88oIADSt/oHtSDnEUG/f6IoNHZ5aXRYbzwxY7OOh1NyeRork whYmv8gxPsBqGdzRkuC3wEN8Nym146NY4VsdC7sebukUvx6bn+DgdqqPF N5qnu5XOoZtS9mMM4v5UkhT9G9xQiqtsXMqSS+y9xs92YotXsn7Y1mJLB Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10998"; a="3428673" X-IronPort-AV: E=Sophos;i="6.06,191,1705392000"; d="scan'208";a="3428673" 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240228_124941_729506_FC6F519A X-CRM114-Status: GOOD ( 12.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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)