From patchwork Fri Jul 21 17:00:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13322382 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EB06EB64DC for ; Fri, 21 Jul 2023 17:00:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230309AbjGURAY (ORCPT ); Fri, 21 Jul 2023 13:00:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230471AbjGURAW (ORCPT ); Fri, 21 Jul 2023 13:00:22 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC29230D4; Fri, 21 Jul 2023 10:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689958821; x=1721494821; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RBL/WYJF2pgAGN2U87+I/5wNQ/TVlUj5uO/xGqVLkms=; b=VRB7gyB3WP63ltdkJPNxq6+iB0JxF+Egl+YWy/BCtKcDqmezHtU5B9yb 87gFMkbH39a7BUAn+SE37O8TyyS39ETbWOSwcSGgoJGO7S+9nQLQWlvHg s5k4w2EmZd/WLjy5umayzOFMmceeRRBZKpxJ+jcZXMc/UpCmCOLCV4uSr z9xln9UMrohsmmvR5JYouvQEUkvh8F59yH5sMYoWYanrL7LGSBTRkbXdI GVPj3HIsNXKGdKa6RCi9Vu4OLJKL8a7DN75vg822kO+E4MqcI1N39SPgu gG2KsNeaP4a8AxVKFYSDHQodsmNVDkg6klsyfw04LRCNv+0340LQPJeto Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="369739459" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="369739459" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 10:00:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="754540195" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="754540195" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 21 Jul 2023 10:00:15 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 2ED1117D; Fri, 21 Jul 2023 20:00:23 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Nuno Sa Subject: [PATCH v2 1/8] iio: core: Add opaque_struct_size() helper and use it Date: Fri, 21 Jul 2023 20:00:15 +0300 Message-Id: <20230721170022.3461-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> References: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Introduce opaque_struct_size() helper, which may be moved to overflow.h in the future, and use it in the IIO core. Cc: Uwe Kleine-König Signed-off-by: Andy Shevchenko Reviewed-by: Nuno Sa --- drivers/iio/industrialio-core.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index c117f50d0cf3..6cca86fd0ef9 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1617,6 +1617,28 @@ const struct device_type iio_device_type = { .release = iio_dev_release, }; +/** + * opaque_struct_size() - Calculate size of opaque structure with trailing aligned data. + * @p: Pointer to the opaque structure. + * @a: Alignment in bytes before trailing data. + * @s: Data size in bytes (can be 0). + * + * Calculates size of memory needed for structure of @p followed by the aligned data + * of size @s. When @s is 0, the alignment @a is not taken into account and the result + * is an equivalent to sizeof(*(@p)). + * + * Returns: Number of bytes needed or SIZE_MAX on overflow. + */ +#define opaque_struct_size(p, a, s) ({ \ + size_t _psize = sizeof(*(p)); \ + size_t _asize = ALIGN(_psize, (a)); \ + size_t _ssize = s; \ + _ssize ? size_add(_asize, _ssize) : _psize; \ +}) + +#define opaque_struct_data(p, a) \ + ((void *)(p) + ALIGN(sizeof(*(p)), (a))) + /** * iio_device_alloc() - allocate an iio_dev from a driver * @parent: Parent device. @@ -1628,19 +1650,13 @@ 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; - } - + alloc_size = opaque_struct_size(iio_dev_opaque, IIO_DMA_MINALIGN, sizeof_priv); iio_dev_opaque = kzalloc(alloc_size, GFP_KERNEL); if (!iio_dev_opaque) 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); + indio_dev->priv = opaque_struct_data(iio_dev_opaque, IIO_DMA_MINALIGN); indio_dev->dev.parent = parent; indio_dev->dev.type = &iio_device_type; From patchwork Fri Jul 21 17:00:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13322381 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7593AEB64DD for ; Fri, 21 Jul 2023 17:00:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230515AbjGURAX (ORCPT ); Fri, 21 Jul 2023 13:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230268AbjGURAV (ORCPT ); Fri, 21 Jul 2023 13:00:21 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 483802D77; Fri, 21 Jul 2023 10:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689958820; x=1721494820; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5nJHjGERAW3jaXOKzutpblot6hKhdh8NmrgkghAWl1s=; b=dG7VBNAYX/Ldi1EXZKu3gKexBGtTDt3rUvfKueJL3HAw+4+lpUffy7g+ OBB2sKvKChX4+MjdRCi9zWL/sePKYmDMrltaKtpuO0ZwdPgoRF+Wu68kB +MTlDoElTwTwFygKDxIJB4yWEsF6lmXJlVSsj4gCJFvfLlqMpuPsyCbMi k8gEra+rbPOb2oCaE/cCgYStrJQBzOAw7M/cdbx7buzyQdFKbVWBwNg1x Xy8/7OsHWaujERvGBa20JrXm35Ipd0AEsCfkLBPwAQENH28Z+WwvLJOcj QudIKMSgWkEyOHM88c2oTq1C5d052U50NacG9sUVV7fAcvtE2gUK64/lU g==; X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="453443908" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="453443908" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 10:00:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="675106518" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="675106518" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 21 Jul 2023 10:00:15 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 426A542D; Fri, 21 Jul 2023 20:00:23 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Nuno Sa Subject: [PATCH v2 2/8] iio: core: Use sysfs_match_string() helper Date: Fri, 21 Jul 2023 20:00:16 +0300 Message-Id: <20230721170022.3461-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> References: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Use sysfs_match_string() helper instead of open coded variant. Signed-off-by: Andy Shevchenko Reviewed-by: Nuno Sa --- drivers/iio/industrialio-core.c | 81 +++++++++++++-------------------- 1 file changed, 31 insertions(+), 50 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 6cca86fd0ef9..4e45740331ee 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1400,50 +1400,32 @@ static ssize_t label_show(struct device *dev, struct device_attribute *attr, static DEVICE_ATTR_RO(label); +static const char * const clock_names[] = { + [CLOCK_REALTIME] = "realtime", + [CLOCK_MONOTONIC] = "monotonic", + [CLOCK_PROCESS_CPUTIME_ID] = "process_cputime_id", + [CLOCK_THREAD_CPUTIME_ID] = "thread_cputime_id", + [CLOCK_MONOTONIC_RAW] = "monotonic_raw", + [CLOCK_REALTIME_COARSE] = "realtime_coarse", + [CLOCK_MONOTONIC_COARSE] = "monotonic_coarse", + [CLOCK_BOOTTIME] = "boottime", + [CLOCK_REALTIME_ALARM] = "realtime_alarm", + [CLOCK_BOOTTIME_ALARM] = "boottime_alarm", + [CLOCK_SGI_CYCLE] = "sgi_cycle", + [CLOCK_TAI] = "tai", +}; + static ssize_t current_timestamp_clock_show(struct device *dev, struct device_attribute *attr, char *buf) { const struct iio_dev *indio_dev = dev_to_iio_dev(dev); const clockid_t clk = iio_device_get_clock(indio_dev); - const char *name; - ssize_t sz; - switch (clk) { - case CLOCK_REALTIME: - name = "realtime\n"; - sz = sizeof("realtime\n"); - break; - case CLOCK_MONOTONIC: - name = "monotonic\n"; - sz = sizeof("monotonic\n"); - break; - case CLOCK_MONOTONIC_RAW: - name = "monotonic_raw\n"; - sz = sizeof("monotonic_raw\n"); - break; - case CLOCK_REALTIME_COARSE: - name = "realtime_coarse\n"; - sz = sizeof("realtime_coarse\n"); - break; - case CLOCK_MONOTONIC_COARSE: - name = "monotonic_coarse\n"; - sz = sizeof("monotonic_coarse\n"); - break; - case CLOCK_BOOTTIME: - name = "boottime\n"; - sz = sizeof("boottime\n"); - break; - case CLOCK_TAI: - name = "tai\n"; - sz = sizeof("tai\n"); - break; - default: + if (clk < 0 && clk >= ARRAY_SIZE(clock_names)) BUG(); - } - memcpy(buf, name, sz); - return sz; + return sysfs_emit(buf, "%s\n", clock_names[clk]); } static ssize_t current_timestamp_clock_store(struct device *dev, @@ -1453,22 +1435,21 @@ static ssize_t current_timestamp_clock_store(struct device *dev, clockid_t clk; int ret; - if (sysfs_streq(buf, "realtime")) - clk = CLOCK_REALTIME; - else if (sysfs_streq(buf, "monotonic")) - clk = CLOCK_MONOTONIC; - else if (sysfs_streq(buf, "monotonic_raw")) - clk = CLOCK_MONOTONIC_RAW; - else if (sysfs_streq(buf, "realtime_coarse")) - clk = CLOCK_REALTIME_COARSE; - else if (sysfs_streq(buf, "monotonic_coarse")) - clk = CLOCK_MONOTONIC_COARSE; - else if (sysfs_streq(buf, "boottime")) - clk = CLOCK_BOOTTIME; - else if (sysfs_streq(buf, "tai")) - clk = CLOCK_TAI; - else + ret = sysfs_match_string(clock_names, buf); + if (ret < 0) + return ret; + + switch (ret) { + case CLOCK_PROCESS_CPUTIME_ID: + case CLOCK_THREAD_CPUTIME_ID: + case CLOCK_REALTIME_ALARM: + case CLOCK_BOOTTIME_ALARM: + case CLOCK_SGI_CYCLE: return -EINVAL; + default: + clk = ret; + break; + } ret = iio_device_set_clock(dev_to_iio_dev(dev), clk); if (ret) From patchwork Fri Jul 21 17:00:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13322380 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BA4DC001DE for ; Fri, 21 Jul 2023 17:00:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230499AbjGURAY (ORCPT ); Fri, 21 Jul 2023 13:00:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230463AbjGURAW (ORCPT ); Fri, 21 Jul 2023 13:00:22 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E7AC2D53; Fri, 21 Jul 2023 10:00:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689958820; x=1721494820; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FZ6LKlQ1eKLJzZ117OvZPucOMpZOmzPiCLf/Siw2rWo=; b=OlfaOZQqD7SWfDs2krTBGODU2UjugIcq7tBkmsIQTPkSeb4+Urfg7U1a Gu9aQWakytlcSaQacR5cFqEJ/gBjHuHBp82lI9UNdXBgshKhNufyBQukq gEZXAYDJBuPK8rsHStQmakgW+B1hkNSdQTaQxR4e55TL14AhIsko+KcGI wlz6j6iZgzYEEPZbZo7EoZvhCUbe6zfscA0tj89QUa8iwHifpSkT6hipF 21Mwx3rH9QEvHU9vElG1YSoI1i0o05Qm5s0/n/GAPCYsmBzqV1ykexyIE C+khHwaJnbzbYBCEHonvOXpW73n+zU4PGBZ3uwjm8v26xllpFIIcWDTB+ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="369739454" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="369739454" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 10:00:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="754540194" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="754540194" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 21 Jul 2023 10:00:15 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 4CD74370; Fri, 21 Jul 2023 20:00:23 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Nuno Sa Subject: [PATCH v2 3/8] iio: core: Switch to krealloc_array() Date: Fri, 21 Jul 2023 20:00:17 +0300 Message-Id: <20230721170022.3461-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> References: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Let the krealloc_array() copy the original data and check for a multiplication overflow. Signed-off-by: Andy Shevchenko Reviewed-by: Nuno Sa --- drivers/iio/industrialio-core.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 4e45740331ee..6e28c2a3d223 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1465,7 +1465,7 @@ int iio_device_register_sysfs_group(struct iio_dev *indio_dev, const struct attribute_group **new, **old = iio_dev_opaque->groups; unsigned int cnt = iio_dev_opaque->groupcounter; - new = krealloc(old, sizeof(*new) * (cnt + 2), GFP_KERNEL); + new = krealloc_array(old, cnt + 2, sizeof(*new), GFP_KERNEL); if (!new) return -ENOMEM; @@ -1483,13 +1483,13 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev) { struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); int i, ret = 0, attrcount, attrn, attrcount_orig = 0; + struct attribute **attrs, **attr, *clk = NULL; struct iio_dev_attr *p; - struct attribute **attr, *clk = NULL; /* First count elements in any existing group */ - if (indio_dev->info->attrs) { - attr = indio_dev->info->attrs->attrs; - while (*attr++ != NULL) + attrs = indio_dev->info->attrs ? indio_dev->info->attrs->attrs : NULL; + if (attrs) { + for (attr = attrs; *attr; attr++) attrcount_orig++; } attrcount = attrcount_orig; @@ -1521,20 +1521,14 @@ static int iio_device_register_sysfs(struct iio_dev *indio_dev) if (clk) attrcount++; + /* Copy across original attributes, and point to original binary attributes */ iio_dev_opaque->chan_attr_group.attrs = - kcalloc(attrcount + 1, - sizeof(iio_dev_opaque->chan_attr_group.attrs[0]), - GFP_KERNEL); + krealloc_array(attrs, attrcount + 1, sizeof(*attrs), GFP_KERNEL); if (iio_dev_opaque->chan_attr_group.attrs == NULL) { ret = -ENOMEM; goto error_clear_attrs; } - /* Copy across original attributes, and point to original binary attributes */ if (indio_dev->info->attrs) { - memcpy(iio_dev_opaque->chan_attr_group.attrs, - indio_dev->info->attrs->attrs, - sizeof(iio_dev_opaque->chan_attr_group.attrs[0]) - *attrcount_orig); iio_dev_opaque->chan_attr_group.is_visible = indio_dev->info->attrs->is_visible; iio_dev_opaque->chan_attr_group.bin_attrs = From patchwork Fri Jul 21 17:00:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13322379 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B2393C001DC for ; Fri, 21 Jul 2023 17:00:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230484AbjGURAW (ORCPT ); Fri, 21 Jul 2023 13:00:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230327AbjGURAU (ORCPT ); Fri, 21 Jul 2023 13:00:20 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2CBE26A0; Fri, 21 Jul 2023 10:00:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689958818; x=1721494818; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UZLQH0kViux9VJJxBn8faoSNy7gR7pEqp4KmqCGfoYU=; b=R3GGX5vnHWgT7f+TO9myhR7lxYMIEzh33BtzFngVA9TMR/wB9Wud2Aka XixqJ6qfkfWUxsk46BSau0sNO+uvwnqrHkJ92g9PAJmXQX9F+3a6pIFgc oDc/QOiW+XZIN1lR5tviy+VJwabvwsvDFyzxqMrPJUnJi9uMg8UE/k2fd W0tagzMUzIE9zZrAohKsDlyUQPE5sEcm39cCGK/u+1P7vDnQIML1yvoU6 HreOArqOUCV6CfalsLbIOUvd5n+rXAFLgJkrpNt1PpZ89toKi+mL61bAt 35k/ybFoX8b64EDv7kYcsBXp/SjawXVlucacDRHWbWHhEuD06VH+qPC3b w==; X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="369739466" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="369739466" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 10:00:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="754540196" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="754540196" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 21 Jul 2023 10:00:15 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 609895FC; Fri, 21 Jul 2023 20:00:23 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Nuno Sa Subject: [PATCH v2 4/8] iio: core: Use min() instead of min_t() to make code more robust Date: Fri, 21 Jul 2023 20:00:18 +0300 Message-Id: <20230721170022.3461-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> References: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org min() has strict type checking and preferred over min_t() for unsigned types to avoid overflow. Here it's unclear why min_t() was chosen since both variables are of the same type. In any case update to use min(). Signed-off-by: Andy Shevchenko Reviewed-by: Nuno Sa --- drivers/iio/industrialio-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 6e28c2a3d223..78cc67efa490 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -389,7 +389,7 @@ static ssize_t iio_debugfs_write_reg(struct file *file, char buf[80]; int ret; - count = min_t(size_t, count, (sizeof(buf)-1)); + count = min(count, sizeof(buf) - 1); if (copy_from_user(buf, userbuf, count)) return -EFAULT; From patchwork Fri Jul 21 17:00:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13322384 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 035A3EB64DC for ; Fri, 21 Jul 2023 17:00:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231158AbjGURA0 (ORCPT ); Fri, 21 Jul 2023 13:00:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230107AbjGURAZ (ORCPT ); Fri, 21 Jul 2023 13:00:25 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4475D2D50; Fri, 21 Jul 2023 10:00:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689958822; x=1721494822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=325fM0IBOgfY/NJbM2dkuOlixnwd7vBQ+WpRaNaNsK8=; b=gxxPMgVVf1JbTpB/O0sLo1UMWeWa/WioPDv+UN2tKOBoHQ/tIM6yS4yB zdG6SvnynUs935J51NsCXczSQqheCWIkdzNruU1etRintTPYQB7RFjD2Q 9/VINPXhpFc3WluXAutFQXJmpKRwBm6S7SA61+9oFyyHhcI9CKWwkb++e wxdeWr17cvHLLt7FO5s7AELfe6d90WEaZMMJl3S2NxCkFywJkgUXhBuO8 IDOJb8uICqxOcHcNLbl27FAoarj71jaBMRKX5OkQ8GkLwKfS/IHWjvhHn atwRpvXk0itS1JCw8igUnWM8shNiVFBgzzEoHlyP/QRgpeXndZNWUsDZO w==; X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="369739478" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="369739478" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 10:00:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="754540212" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="754540212" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 21 Jul 2023 10:00:18 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 6E87E604; Fri, 21 Jul 2023 20:00:23 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Nuno Sa Subject: [PATCH v2 5/8] iio: core: Get rid of redundant 'else' Date: Fri, 21 Jul 2023 20:00:19 +0300 Message-Id: <20230721170022.3461-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> References: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org In the snippets like the following if (...) return / goto / break / continue ...; else ... the 'else' is redundant. Get rid of it. Signed-off-by: Andy Shevchenko Reviewed-by: Nuno Sa --- drivers/iio/industrialio-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 78cc67efa490..66cea23df7e0 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -524,7 +524,7 @@ ssize_t iio_enum_read(struct iio_dev *indio_dev, i = e->get(indio_dev, chan); if (i < 0) return i; - else if (i >= e->num_items || !e->items[i]) + if (i >= e->num_items || !e->items[i]) return -EINVAL; return sysfs_emit(buf, "%s\n", e->items[i]); @@ -1217,7 +1217,7 @@ static int iio_device_add_info_mask_type(struct iio_dev *indio_dev, &iio_dev_opaque->channel_attr_list); if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE)) continue; - else if (ret < 0) + if (ret < 0) return ret; attrcount++; } @@ -1255,7 +1255,7 @@ static int iio_device_add_info_mask_type_avail(struct iio_dev *indio_dev, kfree(avail_postfix); if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE)) continue; - else if (ret < 0) + if (ret < 0) return ret; attrcount++; } From patchwork Fri Jul 21 17:00:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13322386 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A62A7C001DE for ; Fri, 21 Jul 2023 17:00:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231250AbjGURA3 (ORCPT ); Fri, 21 Jul 2023 13:00:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231166AbjGURA0 (ORCPT ); Fri, 21 Jul 2023 13:00:26 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4D712D51; Fri, 21 Jul 2023 10:00:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689958822; x=1721494822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=T3XCTeFPAAlE3o8HaU8QjcX7N6rcLUJEWl9U9IJiSCU=; b=lLMQjffvtZR+2dHaF/m8iHVcgSsDh9b0HglP2T0gz/4ZDRD/GTMYOF0p +VRdb347xUL5MCLwgz3pmJjmPMyu1K2m3rhw4kRrFALEEPxevEjiwm12x DsIW/nB+LhnrYocICim14FRp3ezsaYP24W/q3wpZgpx1BelEuc6COSZFH GEL/m8voLyIgWYm12iquthdAgwbobzwkP7PVHcNbcMRBaJG/cGIa0EA0y D4ipuvai7+vR/oNo3EWURal20IV3pWUiapeKgbtp1mdiMTpqrYqdJZ4Y5 KnH2H0kP+MTw0qRl/cZKTVf6JJSw/4ySDzc9e3uJJFv6eA2NlTQrjVmR1 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="369739486" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="369739486" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 10:00:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="754540213" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="754540213" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 21 Jul 2023 10:00:18 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 78376516; Fri, 21 Jul 2023 20:00:23 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Nuno Sa Subject: [PATCH v2 6/8] iio: core: Fix issues and style of the comments Date: Fri, 21 Jul 2023 20:00:20 +0300 Message-Id: <20230721170022.3461-7-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> References: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org The `scripts/kernel-doc -v -none -Wall` reports several issues with the kernel doc in IIO core C file. Update the comments accordingly. Signed-off-by: Andy Shevchenko Reviewed-by: Nuno Sa Reviewed-by: Randy Dunlap --- drivers/iio/industrialio-core.c | 57 +++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 66cea23df7e0..a9b9804097ab 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only -/* The industrial I/O core +/* + * The industrial I/O core * * Copyright (c) 2008 Jonathan Cameron * @@ -183,7 +184,9 @@ static const char * const iio_chan_info_postfix[] = { * @indio_dev: Device structure whose ID is being queried * * The IIO device ID is a unique index used for example for the naming - * of the character device /dev/iio\:device[ID] + * of the character device /dev/iio\:device[ID]. + * + * Returns: Unique ID for the device. */ int iio_device_id(struct iio_dev *indio_dev) { @@ -196,6 +199,8 @@ EXPORT_SYMBOL_GPL(iio_device_id); /** * iio_buffer_enabled() - helper function to test if the buffer is enabled * @indio_dev: IIO device structure for device + * + * Returns: True, if the buffer is enabled. */ bool iio_buffer_enabled(struct iio_dev *indio_dev) { @@ -225,6 +230,9 @@ EXPORT_SYMBOL_GPL(iio_get_debugfs_dentry); * iio_find_channel_from_si() - get channel from its scan index * @indio_dev: device * @si: scan index to match + * + * Returns: + * Constant pointer to iio_chan_spec, if scan index matches, NULL on failure. */ const struct iio_chan_spec *iio_find_channel_from_si(struct iio_dev *indio_dev, int si) @@ -249,7 +257,9 @@ EXPORT_SYMBOL(iio_read_const_attr); /** * iio_device_set_clock() - Set current timestamping clock for the device * @indio_dev: IIO device structure containing the device - * @clock_id: timestamping clock posix identifier to set. + * @clock_id: timestamping clock POSIX identifier to set. + * + * Returns: 0 on success, or a negative error code. */ int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id) { @@ -275,6 +285,8 @@ EXPORT_SYMBOL(iio_device_set_clock); /** * iio_device_get_clock() - Retrieve current timestamping clock for the device * @indio_dev: IIO device structure containing the device + * + * Returns: Clock ID of the current timestamping clock for the device. */ clockid_t iio_device_get_clock(const struct iio_dev *indio_dev) { @@ -287,6 +299,8 @@ EXPORT_SYMBOL(iio_device_get_clock); /** * iio_get_time_ns() - utility function to get a time stamp for events etc * @indio_dev: device + * + * Returns: Timestamp of the event in nanoseconds. */ s64 iio_get_time_ns(const struct iio_dev *indio_dev) { @@ -594,7 +608,7 @@ EXPORT_SYMBOL_GPL(iio_show_mount_matrix); * If device is assigned no mounting matrix property, a default 3x3 identity * matrix will be filled in. * - * Return: 0 if success, or a negative error code on failure. + * Returns: 0 if success, or a negative error code on failure. */ int iio_read_mount_matrix(struct device *dev, struct iio_mount_matrix *matrix) { @@ -692,9 +706,9 @@ static ssize_t __iio_format_value(char *buf, size_t offset, unsigned int type, * @vals: Pointer to the values, exact meaning depends on the * type parameter. * - * Return: 0 by default, a negative number on failure or the - * total number of characters written for a type that belongs - * to the IIO_VAL_* constant. + * Returns: + * 0 by default, a negative number on failure or the total number of characters + * written for a type that belongs to the IIO_VAL_* constant. */ ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals) { @@ -847,8 +861,8 @@ static ssize_t iio_read_channel_info_avail(struct device *dev, * @fract: The fractional part of the number * @scale_db: True if this should parse as dB * - * Returns 0 on success, or a negative error code if the string could not be - * parsed. + * Returns: + * 0 on success, or a negative error code if the string could not be parsed. */ static int __iio_str_to_fixpoint(const char *str, int fract_mult, int *integer, int *fract, bool scale_db) @@ -917,8 +931,8 @@ static int __iio_str_to_fixpoint(const char *str, int fract_mult, * @integer: The integer part of the number * @fract: The fractional part of the number * - * Returns 0 on success, or a negative error code if the string could not be - * parsed. + * Returns: + * 0 on success, or a negative error code if the string could not be parsed. */ int iio_str_to_fixpoint(const char *str, int fract_mult, int *integer, int *fract) @@ -1618,7 +1632,10 @@ const struct device_type iio_device_type = { * iio_device_alloc() - allocate an iio_dev from a driver * @parent: Parent device. * @sizeof_priv: Space to allocate for private structure. - **/ + * + * Returns: + * Pointer to allocated iio_dev on success, NULL on failure. + */ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv) { struct iio_dev_opaque *iio_dev_opaque; @@ -1668,7 +1685,7 @@ EXPORT_SYMBOL(iio_device_alloc); /** * iio_device_free() - free an iio_dev from a driver * @dev: the iio_dev associated with the device - **/ + */ void iio_device_free(struct iio_dev *dev) { if (dev) @@ -1689,7 +1706,7 @@ static void devm_iio_device_release(void *iio_dev) * Managed iio_device_alloc. iio_dev allocated with this function is * automatically freed on driver detach. * - * RETURNS: + * Returns: * Pointer to allocated iio_dev on success, NULL on failure. */ struct iio_dev *devm_iio_device_alloc(struct device *parent, int sizeof_priv) @@ -1716,8 +1733,8 @@ EXPORT_SYMBOL_GPL(devm_iio_device_alloc); * @filp: File structure for iio device used to keep and later access * private data * - * Return: 0 on success or -EBUSY if the device is already opened - **/ + * Returns: 0 on success or -EBUSY if the device is already opened + */ static int iio_chrdev_open(struct inode *inode, struct file *filp) { struct iio_dev_opaque *iio_dev_opaque = @@ -1750,7 +1767,7 @@ static int iio_chrdev_open(struct inode *inode, struct file *filp) * @inode: Inode structure pointer for the char device * @filp: File structure pointer for the char device * - * Return: 0 for successful release + * Returns: 0 for successful release. */ static int iio_chrdev_release(struct inode *inode, struct file *filp) { @@ -1789,7 +1806,7 @@ static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) mutex_lock(&iio_dev_opaque->info_exist_lock); - /** + /* * The NULL check here is required to prevent crashing when a device * is being removed while userspace would still have open file handles * to try to access this device. @@ -1966,7 +1983,7 @@ EXPORT_SYMBOL(__iio_device_register); /** * iio_device_unregister() - unregister a device from the IIO subsystem * @indio_dev: Device structure representing the device. - **/ + */ void iio_device_unregister(struct iio_dev *indio_dev) { struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); @@ -2017,7 +2034,7 @@ EXPORT_SYMBOL_GPL(__devm_iio_device_register); * * Use with iio_device_release_direct_mode() * - * Returns: 0 on success, -EBUSY on failure + * Returns: 0 on success, -EBUSY on failure. */ int iio_device_claim_direct_mode(struct iio_dev *indio_dev) { From patchwork Fri Jul 21 17:00:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13322383 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 718EDC00528 for ; Fri, 21 Jul 2023 17:00:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231180AbjGURAZ (ORCPT ); Fri, 21 Jul 2023 13:00:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbjGURAY (ORCPT ); Fri, 21 Jul 2023 13:00:24 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73F7426A0; Fri, 21 Jul 2023 10:00:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689958821; x=1721494821; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KFTy3k5fjmzvEVapIibfwY9OKXik6UjBLw7ZmKrmWGc=; b=mujet7A7G3cW9RxjpJlxrLBXPxjpvfvbbNyXEUS9B7UDoMPOlJIpwUW3 PcLMSKN73OoIPB1yv2tNMiv4ohaH4J9wbufRWLtqyZedbcAm0fkumTmiZ KWICt0RDZFOSx/mVlxFKuFVDhmdQl4NfbZxQH4BqENv2he2Y5pil368K5 KeD1yFT1w/7CjthkQh1AOSi51025Ke/nNBy9cdVmhGmTQjYv15xBOPI39 eYf2Rp/ToISCDt5xiQdzPbVxtGumbFJevh1phIKmT+nk7MYTcd7Bs7OhE YiNWQgmlckpcCFQFDBgz5QJBBwutxA6c3oeHqXnujyF79eZR8zpavQivx Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="453443965" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="453443965" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 10:00:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="675106536" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="675106536" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 21 Jul 2023 10:00:18 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 7D2F866C; Fri, 21 Jul 2023 20:00:23 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Nuno Sa Subject: [PATCH v2 7/8] iio: core: Move initcalls closer to the respective calls Date: Fri, 21 Jul 2023 20:00:21 +0300 Message-Id: <20230721170022.3461-8-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> References: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Move subsys_initcall() and module_exit() closer to the respective calls. 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 a9b9804097ab..5c9c68d69fc6 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -354,6 +354,7 @@ static int __init iio_init(void) error_nothing: return ret; } +subsys_initcall(iio_init); static void __exit iio_exit(void) { @@ -362,6 +363,7 @@ static void __exit iio_exit(void) bus_unregister(&iio_bus_type); debugfs_remove(iio_debugfs_dentry); } +module_exit(iio_exit); #if defined(CONFIG_DEBUG_FS) static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf, @@ -2118,9 +2120,6 @@ int iio_device_get_current_mode(struct iio_dev *indio_dev) } EXPORT_SYMBOL_GPL(iio_device_get_current_mode); -subsys_initcall(iio_init); -module_exit(iio_exit); - MODULE_AUTHOR("Jonathan Cameron "); MODULE_DESCRIPTION("Industrial I/O core"); MODULE_LICENSE("GPL"); From patchwork Fri Jul 21 17:00:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 13322385 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDF1EEB64DD for ; Fri, 21 Jul 2023 17:00:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231246AbjGURA2 (ORCPT ); Fri, 21 Jul 2023 13:00:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231197AbjGURA0 (ORCPT ); Fri, 21 Jul 2023 13:00:26 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C53962D53; Fri, 21 Jul 2023 10:00:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689958822; x=1721494822; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/foF2WXy3sLwO5FNP6HwLNSDaxhXkIAkyYPFiKkl/9I=; b=dcdysi9UIF59ioef9yEo0G/TLTe/+CJDffBPPt4MdQWp/RFxdQe58pKn nMSK6JnPswZ1cfW6BQx+G5Lgjy9lk+BtEqY2dEnronWTLSabo9EOPYljX 5vmsDe1ylNvAWgHGLOREpb026lYoijVd3YBVHdiwIzqva1Qlqbo2PgAKy BUBxnyeq2WhDMz4t7vwDKX2/qJfZgJk9BGSiyUcN1myGNJiz9wjqzts4z 60+6/X0VhQqu0IwbCvAQhm61eKFd1yDZ9RJEydfUQ+VwlZv6Qp8t0DzK7 73osIS0TyHfCXmymMhOKZTVQEVym2KdTUlEehgaPPLJufj8qVwN8Ky8gw A==; X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="369739492" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="369739492" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2023 10:00:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10778"; a="754540217" X-IronPort-AV: E=Sophos;i="6.01,222,1684825200"; d="scan'208";a="754540217" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 21 Jul 2023 10:00:18 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 8ABF769F; Fri, 21 Jul 2023 20:00:23 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen , Nuno Sa Subject: [PATCH v2 8/8] iio: core: Improve indentation in a few places Date: Fri, 21 Jul 2023 20:00:22 +0300 Message-Id: <20230721170022.3461-9-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> References: <20230721170022.3461-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Improve an indentation in a few places to increase readability. Signed-off-by: Andy Shevchenko Reviewed-by: Nuno Sa --- drivers/iio/industrialio-core.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index 5c9c68d69fc6..e1293fdbc0ef 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -206,9 +206,9 @@ bool iio_buffer_enabled(struct iio_dev *indio_dev) { struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); - return iio_dev_opaque->currentmode - & (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE | - INDIO_BUFFER_SOFTWARE); + return iio_dev_opaque->currentmode & + (INDIO_BUFFER_HARDWARE | INDIO_BUFFER_SOFTWARE | + INDIO_BUFFER_TRIGGERED); } EXPORT_SYMBOL_GPL(iio_buffer_enabled); @@ -388,8 +388,8 @@ static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf, } iio_dev_opaque->read_buf_len = snprintf(iio_dev_opaque->read_buf, - sizeof(iio_dev_opaque->read_buf), - "0x%X\n", val); + sizeof(iio_dev_opaque->read_buf), + "0x%X\n", val); return simple_read_from_buffer(userbuf, count, ppos, iio_dev_opaque->read_buf, @@ -492,8 +492,7 @@ static ssize_t iio_read_channel_ext_info(struct device *dev, static ssize_t iio_write_channel_ext_info(struct device *dev, struct device_attribute *attr, - const char *buf, - size_t len) + const char *buf, size_t len) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); @@ -585,9 +584,9 @@ static int iio_setup_mount_idmatrix(const struct device *dev, ssize_t iio_show_mount_matrix(struct iio_dev *indio_dev, uintptr_t priv, const struct iio_chan_spec *chan, char *buf) { - const struct iio_mount_matrix *mtx = ((iio_get_mount_matrix_t *) - priv)(indio_dev, chan); + const struct iio_mount_matrix *mtx; + mtx = ((iio_get_mount_matrix_t *)priv)(indio_dev, chan); if (IS_ERR(mtx)) return PTR_ERR(mtx); @@ -1025,14 +1024,12 @@ int __iio_device_attr_init(struct device_attribute *dev_attr, if (chan->modified && (shared_by == IIO_SEPARATE)) { if (chan->extend_name) full_postfix = kasprintf(GFP_KERNEL, "%s_%s_%s", - iio_modifier_names[chan - ->channel2], + iio_modifier_names[chan->channel2], chan->extend_name, postfix); else full_postfix = kasprintf(GFP_KERNEL, "%s_%s", - iio_modifier_names[chan - ->channel2], + iio_modifier_names[chan->channel2], postfix); } else { if (chan->extend_name == NULL || shared_by != IIO_SEPARATE)