From patchwork Mon Mar 4 14:04: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: 13580652 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 19BA23FB1D; Mon, 4 Mar 2024 14:06:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709561219; cv=none; b=UvGMPfHuiPh2nogQzJnrKChHpg+kTTFOuYQFWXwpto85eq/XkJceK8w7NQOMWMz5Y6TCfkl3E5TkDRhrEuWWwXaab6u6g7FIvVFWxcydMXfcA0WNc2x0c0sEx00woMY/LIGopY8Z/HG2q1nQgXY3MVmzC3+jdb8fsKVo0LBxdyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709561219; c=relaxed/simple; bh=URTHF9Nl3Pd3iMTnwOfXWfyaLmcvXdfv/9NJcJXxRAY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DzvoHGkaz1sk6kx//PBFWydwnRkMir+N80xqDJZS8+hSCVhsd+ueCSoS8OJmXH1wQ8OMQ7O+SrXKQ3XfQZJprCE4+Cxm/y1nLGN5ruHYoQ2Z5dU8erb9jI4DoJ1EfywdnnQvu/nKEWuci3LzHiZL/uKhqpsu+tOStrvbuwF6u2A= 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=Lg1G6v0T; arc=none smtp.client-ip=198.175.65.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="Lg1G6v0T" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709561217; x=1741097217; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=URTHF9Nl3Pd3iMTnwOfXWfyaLmcvXdfv/9NJcJXxRAY=; b=Lg1G6v0Tz+y/h0v2tL3Pn4ONzeuaQVyOzvy72j1HXedqboaNjHfql6gi jScng8tOOvYKEFO1MAqa0RF/W4o7oBaS8lsJNyu1CmIqs41G3ycqH3pZq y3vrq670ZQeAer5Za0P+1rEz62scZpoPLlRfaMdH34ASGy+l9+oUvT6KB NFX2XR3XmkkArDXvHPQqcTIVeLU9TsOn03Jf9F8cMOL53fv+6hl4SF8e8 sZRrWqmhW4AFonEsZbl/q5JeS2pn7/nukJr2n/NwMDh61Mss0+k3vyP8e 5msG/35GxII+02e0BIXp0EMExT7C5icsqYgG7kc0sD1YJsUFcf3ZY6tjb w==; X-IronPort-AV: E=McAfee;i="6600,9927,11002"; a="4214187" X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="4214187" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 06:06:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11002"; a="937040571" X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="937040571" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 04 Mar 2024 06:06:53 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3CED215C; Mon, 4 Mar 2024 16:06:52 +0200 (EET) From: Andy Shevchenko To: Jonathan Cameron , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH v1 1/2] iio: core: Leave private pointer NULL when no private data supplied Date: Mon, 4 Mar 2024 16:04:32 +0200 Message-ID: <20240304140650.977784-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240304140650.977784-1-andriy.shevchenko@linux.intel.com> References: <20240304140650.977784-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-iio@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 point behind the valid data. Leave it NULL when no private data supplied. Fixes: 6d4ebd565d15 ("iio: core: wrap IIO device into an iio_dev_opaque object") Signed-off-by: Andy Shevchenko Reviewed-by: David Lechner --- drivers/iio/industrialio-core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 4302093b92c7..8684ba246969 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1654,8 +1654,10 @@ 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(*iio_dev_opaque), IIO_DMA_MINALIGN); indio_dev->dev.parent = parent; indio_dev->dev.type = &iio_device_type; From patchwork Mon Mar 4 14:04: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: 13580651 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.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 A8F343F9E9; Mon, 4 Mar 2024 14:06:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709561219; cv=none; b=qqIRebjPM4M3dqwrPNrV7y2iLZIcSIT/XKHgzWzCMmc42+7ZfZ38clXA+2KNHOX63KB9es4QHU0/7HhNruXQQIKfqKHm8r7EVOarn6hzl2GBUd6nqyC66MRZgWTwsXWDe3iiBcYk3r3b1JaSOU8w8I8W3+lFdH9z5CwCjcoYGhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709561219; c=relaxed/simple; bh=40hCdHKWv2XHazCffDZwn3ICc74hcXXERftpqKcn6VI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hCZhITKpjjzGLYYBwGK+h9fKFE0stuZywVWgO7BG/sNRd2WS8XeuzI9y2EFukFccAet+j0OnjNW7b0B4HAxuRmZ/2Dw5Xbzj9wZBFsawgarsTSPVTgmdV3V21UxEmClX/eNEYd1PPuw/VWFa10pq2I652SCud//y5l6iM8OTeqE= 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=Of4woBOf; arc=none smtp.client-ip=198.175.65.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="Of4woBOf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709561217; x=1741097217; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=40hCdHKWv2XHazCffDZwn3ICc74hcXXERftpqKcn6VI=; b=Of4woBOf89oUB4qUGe/nyD25L1iwUiOrDJDNzGPMX73ofUuhOYWRWZVF BSYOi8QnKNrlJGcwYSlopUTcUP8/b0fULpMLiiTvV0WJWWyisdw5U2q6a nTOxC57UcJosx8QBOQrEzlxb97oBe6xUSrUjQLjLN37NFrKmD1AapBq0P xEikf6CJu34TM6WSKhTzSvo7dw/mgkHELlLmMY2jKb/o+4GoL4SPoUsxK hdtY/Qb6YgT82CgMbyfLa474+DD1XPUypLLJOMfvpDhBTjBUImgrOsQpw iFsIA19bYbcImiDqQR6GIXVPc6Cuw1F7pKhqQxY/Lx1XtWUyZzDHoCMRT Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11002"; a="4214183" X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="4214183" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 06:06:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,11002"; a="937040570" X-IronPort-AV: E=Sophos;i="6.06,203,1705392000"; d="scan'208";a="937040570" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 04 Mar 2024 06:06:53 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 468883C0; Mon, 4 Mar 2024 16:06:52 +0200 (EET) From: Andy Shevchenko To: Jonathan Cameron , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH v1 2/2] iio: core: Calculate alloc_size only once in iio_device_alloc() Date: Mon, 4 Mar 2024 16:04:33 +0200 Message-ID: <20240304140650.977784-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.43.0.rc1.1.gbec44491f096 In-Reply-To: <20240304140650.977784-1-andriy.shevchenko@linux.intel.com> References: <20240304140650.977784-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-iio@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 Reviewed-by: David Lechner --- 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 8684ba246969..c7ad88932015 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(sizeof(*iio_dev_opaque), IIO_DMA_MINALIGN) + sizeof_priv; + else + alloc_size = sizeof(*iio_dev_opaque); iio_dev_opaque = kzalloc(alloc_size, GFP_KERNEL); if (!iio_dev_opaque)