From patchwork Thu Jul 20 20:53:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 123467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3411664vqt; Thu, 20 Jul 2023 15:20:24 -0700 (PDT) X-Google-Smtp-Source: APBJJlFigr7Lm/7PoQeCAtl2KtMKKKtQPrAHDuS52vsbvfG4Nl3a4j2YBtbr6gywILime6B8Ncef X-Received: by 2002:a05:6402:42c6:b0:51e:5206:d69e with SMTP id i6-20020a05640242c600b0051e5206d69emr7596623edc.10.1689891624568; Thu, 20 Jul 2023 15:20:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689891624; cv=none; d=google.com; s=arc-20160816; b=pk5Fihj+yLLKKWw2ZwWy+Xd/+pYzax34M53U5OPopzUmFswKJF6ZzrO4/rD2otPIG/ 5uFWrxvIvq0DtZG5Pl05uJ5oMFsYGxWwXaBhpCttpCqyEqOa9y4B87uCZ3K93C/FcRyY 0EFHxdwjy5/ZLYI2imgieqc2eB3m72mwHET/8g5xGdzlQjnoaWmokCTGdRJ7f/F18czq VgUjsHclQ8TRv+JKEQEB44FA7J3d0Tj7/CQ4AGSx1jrza1w9fFTvKVslpVAGPbVLuK6N hSr/L0EjDxg7bgD25yAZeDMvYmqVoMywKfn7sv1Zg01DLA3b9L6zL1jSvQ0maST5P3w9 iOsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZFehlCpotwkM8Cs8Ls2VZxJNz2GQvkZ/8bhvuQwow2c=; fh=m5PtcFKsJSrau8Ht3kvrIHfAgOWKJswlcHFlNi8eTJ4=; b=wer0u6RYRt0xzPl8XJjf0VZ4F12MPpiRGUuO/UtYsAMOflEQ/EAMDPnHJgI/dlqq21 dsVEj6G8V/3f0qESHCuvRt74ZyKM4/HdJF78ldu3s81BNCZ5FwbT4tIUQUbGhVfnrHum 5q5yKdyiBkvINxfFNEV/bJUx/RrkXNWDimbr2Wyi5vK5acVj8Lyg9tTqoWTN4Vu0eueS 6OkcWbmEt0ZNSXpBDmq+NZJlF+x/6UcK8VTWWN9AO9jCyup3dSg+b1Lgtd/+gxDxPofo DY+QWYOGCG6fqPq08CCx5q0VaLWxi+mTAneTvQH3oTXQcS/4L/vCdFOgV7wUKVa/37n9 fleg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JfpbwqlF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e5-20020a50fb85000000b0051e25c32d0asi1402908edq.221.2023.07.20.15.20.01; Thu, 20 Jul 2023 15:20:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JfpbwqlF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230078AbjGTUxj (ORCPT + 99 others); Thu, 20 Jul 2023 16:53:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230008AbjGTUxZ (ORCPT ); Thu, 20 Jul 2023 16:53:25 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6C542729; Thu, 20 Jul 2023 13:53:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689886404; x=1721422404; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6VUHMs9iyR3q+BsHrGuAVtYriv4fqBbd4lQJA33WHq0=; b=JfpbwqlF96G/QF7k+Xc/7qpht4pg17L6DWsUq2NBOHcCTk5OLWyYEcUk vWuIadtNpGrdtcGUXSO4eq2u9GOjL4xgtvOmN2/C8qzqExTPROV3tnnBJ ydTDYL16qW73nzBArdacP7/SJIWLB/iqj9fmouv/D+vmb0wIhT0kxWuMY vRTWt6mPgeyGPDC1q/I9UD7mC15dtfonLDPcJdMBVZ2gjxEpMOXZ93GR+ aU2FUyfQztymLUmS9Uxh9GQfqSZun0RxqLqhzT+12Qmrl9OODMp+yeQHc J8DpLv0MHjnK0uUMhReLE1gW4/Ww7yzVUjmSLYg5XxWABXgXAozH2fGjL g==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="356846044" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="356846044" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 13:53:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="838273931" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="838273931" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 20 Jul 2023 13:53:20 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 2DEEC370; Thu, 20 Jul 2023 23:53:28 +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?= Subject: [PATCH v1 1/8] iio: core: Add opaque_struct_size() helper and use it Date: Thu, 20 Jul 2023 23:53:17 +0300 Message-Id: <20230720205324.58702-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> References: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771979800103983486 X-GMAIL-MSGID: 1771979800103983486 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 --- 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 Thu Jul 20 20:53: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: 123449 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3385801vqt; Thu, 20 Jul 2023 14:19:16 -0700 (PDT) X-Google-Smtp-Source: APBJJlG72TSfg6PEUpfNXI+zJmZkmSa0TIE3cuH5m/n1bGmVz9aVtJKMvK3VqSz+g7caalUxMaVj X-Received: by 2002:a05:6402:14c5:b0:51e:2e39:9003 with SMTP id f5-20020a05640214c500b0051e2e399003mr43376edx.40.1689887956512; Thu, 20 Jul 2023 14:19:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689887956; cv=none; d=google.com; s=arc-20160816; b=Q3ID/Epm1Oex0pKL7rqBaXM3N65rtCrOmzyiU/d/VYKWlCqM58ZbsGVlFpO04qXbbj 6D9xONQJltyMEO3Y1QFGVPjd5kAj5UTXCDWn6En36pXdjLuANlux7lIPieeOBi5q8kJ6 ihK7rC0tbIIIao8wlElUxcLCK0DRuLErvtA/OWJH+Efr8F/QSRpZbrlAZD7osQf8iFFo ZfpT/TETO2WmwS2RV2kSuUNxwpFTmh7he0jk/EaCBZ/TDOArJyVzmAupyR9pAodnzZTI 6O9iMxvlMOWju5LCIvEDqnvnux178WLV7uc/Ozz1QMsBuaeIv1v0HevJxu0FPytcJwl7 wmeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=chUuj70DP6XgqQucGfa3UexrQOqmnYEonsbuI3rD2PI=; fh=UOk5tC92rpasvTHsS8FNeq1ESsZGN5rcMuNSzha6ebA=; b=0Fmji+d+yOZwAAvNFsqhiOopgr2OpmLOZT3gD9GlWjqq1L4FVhhYSJj3qTlXM1ObOi Bgj94F1KypL8g9H9u323/Y9ALANmqpgRLHIcxiZeUZc1MBowtMkgGW2g47UH5l6wJ19x jYCmg5Zda3GozBwS6nIPQC3Sb+CnTOn3A6y5g9aS+MSQ66LlfqlXDCEQ2KgW6bVt2gOK VvIf8klkqA7YXBjSpA0Qd7M/4lD9ztSQFcY9in62fywG1IcUMt0DAmA66YvS7chzIscE oPVY0lSdW2d4oXsIB78pz9DKOynZ8Fi4jH5KJvwWivopo9Ennm2tv8uk8oWQI/1n1SYk Jkfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k8rvR7kw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e14-20020a50ec8e000000b0051e3c92a20bsi1514613edr.318.2023.07.20.14.18.52; Thu, 20 Jul 2023 14:19:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=k8rvR7kw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230077AbjGTUx3 (ORCPT + 99 others); Thu, 20 Jul 2023 16:53:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229975AbjGTUxY (ORCPT ); Thu, 20 Jul 2023 16:53:24 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91A67271D; Thu, 20 Jul 2023 13:53:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689886403; x=1721422403; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BwPuQNOSSS/oJufuw512vFJpXnRWfEZI58gglhVJE2c=; b=k8rvR7kwi5R/dty4bsqdfe163hv8KK7HvRoWZIu1TKEPBTfQgZ4PmEYI AgUPC+Ba8XkPa5q9Ls8kX1gfZwp9zrN7uKxer16f80g41rVCXKyXH5j7N PR5MA4Hz5tvztUxkGWMbEPLcjbhzkgb+iEHV/hCZhPVaguiQsqPOre6v1 SjXoSwa0r+9FuepY/nRP7Dv7wjz4kgL82+ptDT6jgd9ftaym1MwS0jZb6 mm61pdUDSDC3WQf1AXQifyjkIG3jhEP2eC6xYE1R28ZG5e+zfp4ZEXHVZ P1hX3QBDL9YQBIxF6JbFtY6KSBBia4L67o1UkO0twxKmr04wNjGIyq5+w w==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="370459741" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="370459741" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 13:53:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="971169131" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="971169131" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 20 Jul 2023 13:53:20 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 37C5693; Thu, 20 Jul 2023 23:53:28 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH v1 2/8] iio: core: Use sysfs_match_string() helper Date: Thu, 20 Jul 2023 23:53:18 +0300 Message-Id: <20230720205324.58702-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> References: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771975954199583032 X-GMAIL-MSGID: 1771975954199583032 Use sysfs_match_string() helper instead of open coded variant. Signed-off-by: Andy Shevchenko --- 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..90e59223b178 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 sprintf(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 Thu Jul 20 20:53: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: 123445 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3379625vqt; Thu, 20 Jul 2023 14:05:59 -0700 (PDT) X-Google-Smtp-Source: APBJJlHNOigKSVhEu6odYaFZGpy9oGbeTJDQQYG44gw8qyfK6scgl5DCEbHiJSXPSvCRR/snkGKO X-Received: by 2002:ac2:4439:0:b0:4f7:6453:f3f1 with SMTP id w25-20020ac24439000000b004f76453f3f1mr2307519lfl.15.1689887158874; Thu, 20 Jul 2023 14:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689887158; cv=none; d=google.com; s=arc-20160816; b=Vb6l9ilef7M83wUcH8ufFv5UYAh1MFTktg1v9Bm3qkOmU8MO7QLqPNWxuzMWN8Lp5M OLISCcEduOWfChbVG+RDBBecu+YVT8DNPRzqHOLbYaIFZJtSZxmuIIO13glktzLp0J/t Ayt2RFI7UAJ3pjfXh0w8MuA17Ysoq3UaJ19Ewfx+Vhj5ARXmdcNe0OP/6SfLCO5hrUEw Lg/J7+jNvlCh5idMRWLqd5i1pzjhAuQT4B34xFgi90yEWj3w9bdbKmorUsKMcdj3nxGd ez3w9lxODGtBWm8TdI3VFCNKEK9KZVqW0PtBCziUWfloI4Ng3MqQRpSh19Kvp5mUk3CP bALA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rxWujKhgJ4rDUawexZo6TUq5ZXWld0TVO73Tp6TSTDU=; fh=UOk5tC92rpasvTHsS8FNeq1ESsZGN5rcMuNSzha6ebA=; b=jmkQoFv82sQ+uj+6YRA9qxCaWaJfdVX2SyXUTwuxov2mxMAVLeltblfrwVxGE8ToTK Weh9B+dqKvYCGQYmV1qVjEll+1lRIBx9brl61oYWFvfC3sI0LuDyFJbONMy9XsXrufls ao7vyeQi/ZlLZTf0u4eRnAucx7Zj0qgmLSNlJaENIH4n3PMAMvK9r/ZU4THXM8ikOtBt qEbT7O/cCgjzBRGyVAE38HsLL3Tbrk4Cg+yqPNrEoY1hYbO0Yq0tSb+I1detWrArdtHp 9894Qkv1uRbZH31z+pSNHwFl5D7hUhAymomQglQDXS5n4DOHWNI7yT+G3Ce9wERMXixZ 2JoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q6LOFcAL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v13-20020a056402184d00b00521a9d1c843si1316072edy.251.2023.07.20.14.05.26; Thu, 20 Jul 2023 14:05:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q6LOFcAL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229975AbjGTUxd (ORCPT + 99 others); Thu, 20 Jul 2023 16:53:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230003AbjGTUxZ (ORCPT ); Thu, 20 Jul 2023 16:53:25 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87B362727; Thu, 20 Jul 2023 13:53:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689886404; x=1721422404; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=X7jl6NvFoo34AY/ks0sUG4wFGR4ZluKuJMLZIOkzWEQ=; b=Q6LOFcALRo2GzbOkyGa0U/2/TvFmUoEe8zfrVkzoNDBu7HMf8ndATBLh VLpUueWSiP+S/QGVbbnUOsG80OzX588SYGPNg6e5WFaot7lZXAr/RNips xNnibfesQZV7hCO9+tmDkl8CKCsTVeTjMwnTRf/rU4hPi8axVXNdX9S8R wck9m2gVKgw1a9PEH6SAcNhU27rdbMuv85Ar1eRPdfhwvOZRJYSzNCGVA NGeszOIZQxTbxTsuZkezGNmTgXPHo959vQkk3NNccTKZNb2aAVNV/cGb+ gcgXi57B58olKdu3B9vKPrjGlm9ATnExMZsCy8TQuKcOmGrrzM8+C0AO4 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="356846041" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="356846041" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 13:53:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="838273932" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="838273932" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 20 Jul 2023 13:53:20 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 47669516; Thu, 20 Jul 2023 23:53:28 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH v1 3/8] iio: core: Switch to krealloc_array() Date: Thu, 20 Jul 2023 23:53:19 +0300 Message-Id: <20230720205324.58702-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> References: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771975117604223278 X-GMAIL-MSGID: 1771975117604223278 Let the krealloc_array() copy the original data and check for a multiplication overflow. Signed-off-by: Andy Shevchenko --- 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 90e59223b178..be154879983e 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 Thu Jul 20 20:53: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: 123454 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3391302vqt; Thu, 20 Jul 2023 14:32:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlFfvJ/0jeD5nfyeHzVjsn8hrT8WHBF71n93GWrr+bVTvhyQxicY7CHV+oNPyr5Vys1hA7Iu X-Received: by 2002:a17:906:1098:b0:989:34a0:45b0 with SMTP id u24-20020a170906109800b0098934a045b0mr7811eju.49.1689888748623; Thu, 20 Jul 2023 14:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689888748; cv=none; d=google.com; s=arc-20160816; b=ze4L9JhqwpWgoIzvU/X6gSEWYWKZcDHdwKvgw8i96fGmxLCweRYwPe0GqeIOh6JarR mofn4tMeyB3aXsQDM2EZqz7gpYWsi5UIGWr5D1L4qKvWk/X5SIrs4W4zbK1GAH1z1ddg RirFCuHgKzd7mATEuZJXCvPaxohBJIIgoJMmeySla8fqZvw1VkSJQnFqFSy7Zx63Hodx 8ZPi0sG/ad5vljFPK7/zPOgPl1gb1pAzyBH0hyA89CUAF6XN0KjexSAGHMy1tm43Nofd WYU3G2d2rXZRuGSiY4FYyjbJkvaMDWwZtDIzW/gi0MKrrA8lodb3D6H+9vDeHEY2jJgz c3rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aFq4IhK0aWlhGuWOPj0qflS6R+EP2adqJUj+qrtt+5E=; fh=UOk5tC92rpasvTHsS8FNeq1ESsZGN5rcMuNSzha6ebA=; b=iURCUGAXqIIDUZ1o+JKGtD4TqOZwGeB3cfFPi6kYoSD+71QOOnk/aAbu9MyjCO1Mna XFSfgxxetj4HimsfDsR+TFFZlULQuJCmXW6mu/BAH9KSwrZiHxfpCD/xlOap5sjKFAkS av2aXAcdDpRfSoJ+FcE5XW+6q8xH6qm/Riw+1zOn/EgQBVLbuteqoQGGENxRck9Wb609 RclsyMIH/CDhzr0tUd6Ve80GLDgvgAx23a/BDi/Vasn0Wj3dDxNStbr/tkoEhdXSkgqP qIqZjlrBUfpvnN54rqPOJQvBPLVC/QL2iM56MyE7onEyiTNDnUnpKY9Iu+DUHzch3ZLS zDuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PguHkZZD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f16-20020a170906049000b00977eb8d769bsi1212359eja.289.2023.07.20.14.32.04; Thu, 20 Jul 2023 14:32:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=PguHkZZD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230018AbjGTUx0 (ORCPT + 99 others); Thu, 20 Jul 2023 16:53:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbjGTUxY (ORCPT ); Thu, 20 Jul 2023 16:53:24 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9192919A6; Thu, 20 Jul 2023 13:53:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689886403; x=1721422403; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cZRvDtegPkJ6Dc6pagLE3ye5wvpxC8MUK6vl7B8hndU=; b=PguHkZZDI9IaFJ/+X1uYuGy9uMVv57tEIOLp1jFO87taNlwzDPUFA/cU ozE4ipYkGBVoSzAgQCSJSRdTcssXfMshO+GZjfs6hhdZ0r8HN5a4Xiikc qIdyJVbi9DpoF5cfBLXWO219PEvJn6PRYlPZRhPOGbJHUgpLoY+/sQ4Zb TF1a8eRSxj8MRm+PQyOsRbFGb8xvGH2yy1MjqBooGI8YpFGP6drsSttVK iOBWkFZiWpIMjwgP1Tnq7k/FVOsVdsO9FA8Xdn3dzLF59OhjbPG0VCCDJ JyKnLh9HyijMKDlciwmHi9OnERbJdmG00wG6cGLDUeL8+5/UCbXoy/HuO g==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="356846038" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="356846038" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 13:53:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="838273934" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="838273934" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 20 Jul 2023 13:53:20 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 536B15FC; Thu, 20 Jul 2023 23:53:28 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH v1 4/8] iio: core: Use min() instead of min_t() to make code more robust Date: Thu, 20 Jul 2023 23:53:20 +0300 Message-Id: <20230720205324.58702-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> References: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771976784698148763 X-GMAIL-MSGID: 1771976784698148763 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 --- 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 be154879983e..9753f6552db4 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 Thu Jul 20 20:53: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: 123450 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3386621vqt; Thu, 20 Jul 2023 14:21:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlHKH85fFTJ/bVjlp+mLKqPvUsYZOAzsxK47VI+hvYCLvLiZzeSOtRN+5ENE5sJizoPIWMIp X-Received: by 2002:a17:906:586:b0:98d:e605:2bce with SMTP id 6-20020a170906058600b0098de6052bcemr3285627ejn.46.1689888069699; Thu, 20 Jul 2023 14:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689888069; cv=none; d=google.com; s=arc-20160816; b=osVKAMvAyKZIgNBokPO6KAE0B7IGaW6lYvFmWPD1aTH+fQ+NNSU9fgiJ8QosjL6WG2 ftpEK0ICgOjjtQqzgVHjKAvEAtY/AwrX5gYYAq9mUfc4Dt9odcyU6Q0z9ZwxGn8SAQgd wo6UwspJZuPmTDTcujqlimKE3dAOM6xVyHO2Yp6azAr0q/qvKdj4Qj1/wTOL79EmD/QV 8OhIeGT6ddVzxrpAPxO3NTVePR9x0bTTNi7sdqrMlN1ZT78cVsY8iJMXWMEwzjy8DhyY p/E458i1Ic6lgAe4478/UX4aUelERFZVv1c0Y1GqMteaJrSpuETz6cmyrRofq8cY5Xak xJSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=j9XohHksyipOe5Ed1szhbSIO3snSm0KvwNF8xCk9jAo=; fh=UOk5tC92rpasvTHsS8FNeq1ESsZGN5rcMuNSzha6ebA=; b=CmjoJfcnlYtVHcjOIlZYZVzSqVT9Ypb3dYGfyJd33AjckVhCqKMlik1DVMA8VTDyQ+ E6LmzxOHWLW2rTrEXQeGDg3mXpy+8cn9+0P/swxdoxWtUl3iVs3CiGpLRs/Lvy3bXbRj nSgLe+iOodBmWBgJAYUIRBE/BXOhhg8i+zpnP21lT0R7Nr99GpOe4llviVAdrT1oDkst fhKzW/nlsbssdwf8n43TjiZUGvIDwRIWsjZPTroeeesae0godRoJmzEcq36/q12+mxUJ o2oedmQ8GEJFbUzSoqA9lA3TfVO2au/cb8Z0LisPL4qSWc5ZEXOSn9LWFsXZ3rnvuPeX kuFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BAfh+zvt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q18-20020a170906b29200b00997c44fb391si1249710ejz.401.2023.07.20.14.20.45; Thu, 20 Jul 2023 14:21:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BAfh+zvt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230154AbjGTUxb (ORCPT + 99 others); Thu, 20 Jul 2023 16:53:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229990AbjGTUxZ (ORCPT ); Thu, 20 Jul 2023 16:53:25 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED8C5271E; Thu, 20 Jul 2023 13:53:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689886403; x=1721422403; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pfv2zMNVzALrxCi0SprgcczDN6aPO4CmhcU5QiAudNo=; b=BAfh+zvtnUMMowZ9gsaM0pbhzSjzIhexmQV6ZxavpwGrv60ViaKP4vsu Nej9d3RSSYXRMVqyTXA9PNWlNB/0phXMFnTldsR187ESTOAeLAUpO0VlV ohnrqeo45MQQyn4ZUALs3DSTAh1OFB6Zd1MeQ9ckKApl/3M3wafXBmtsB NCxMj0Buv3j5AIwVrNPn2hnERW8v1VT6LmXSXLwnxuPoqPKaXArssdaPE OoafJVqWDAlkBNGH6bSFvuK3gNQQalaM03MmwFG0o2y3UQYYjhvLA88Fn hzechwd6IwrLdHa1/mMpfdjYRRbUv+bLJs/5Kd4CzVBmdqma9GDn52vpD A==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="370459744" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="370459744" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 13:53:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="971169133" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="971169133" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 20 Jul 2023 13:53:21 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 5ABE7604; Thu, 20 Jul 2023 23:53:28 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH v1 5/8] iio: core: Get rid of redundant 'else' Date: Thu, 20 Jul 2023 23:53:21 +0300 Message-Id: <20230720205324.58702-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> References: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771976072646000961 X-GMAIL-MSGID: 1771976072646000961 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 --- 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 9753f6552db4..ab9c6db69625 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 Thu Jul 20 20:53: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: 123447 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3384398vqt; Thu, 20 Jul 2023 14:16:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlGwM4AVCNk13AFuKknw8h1AsYiABgqY2/BR3CW0g3mzG7tMsCpY0EcraBQyU09LTM7dHq1M X-Received: by 2002:a17:906:3a9a:b0:993:c48f:184c with SMTP id y26-20020a1709063a9a00b00993c48f184cmr5857317ejd.10.1689887767640; Thu, 20 Jul 2023 14:16:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689887767; cv=none; d=google.com; s=arc-20160816; b=ZOt6VRJ52OyWdjfNKEy4ymyPKI2hFre/KcVTqI+bC/A6Is2XYiE4aI9rrfYdYPy7Bl yDW6h2t3xhCUKV9QOpoJYv/x+c29rlSYoCSYDa7RblBfIQBHiVgtlm98/MVw0lt5qWYb lx2+U9cLG1nuE3XlTQ896Ri7yh1wwCBYmzvBrG5A3jJhqljxqn8S5TzUcOKgjxEtz6lX 8RlaylUhwm9c27f+ITE7Y4rWucdE+lpoLmEmf22sMJzD3dH0GdELDxLa0fWqOV+b+Hfi 1rbiLGn+lE/LKhFSh/2T9SAKcfM02o70xXIuWYrjqoo4WmZhQYyrmKw9tK6/HOBxO5O3 xpHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ly9xwbpnOaFZ7M5MB8+SWd9Shu1ssUlQUhs/9epnXsU=; fh=UOk5tC92rpasvTHsS8FNeq1ESsZGN5rcMuNSzha6ebA=; b=N5oZocd88S9yB/K3xrpg3GsyCKpZO4fzFNf2puJQof2rUuCkhFcuRmArsp+f4FgpwM Zxd6Q4dqpgFnEUirdwUo1kwLS7nvhpHC+Mnnl/yRMpbw08Vm2/OWUOnX5S7+Vmm/DH2Y sNl++RugwVUD1tqQAljDZks4MO2qMVKgzhWbZvhNtQcV4sSiz6lN/N7aocBkGoqavhdQ MrsO1e8OEfHVBoFUx1whsj6RBHeJsYkpilWPqZyWU3eXHpNJZZLDHn+vNx37DWY9cBZ2 GwQQhFDWRvHqORP1ASzZoGS2gqL9XiG5NsmLRSJSo300h5rkNHHu1NopL2YjDXoTawGJ q7pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FmYbKK2M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a170906710500b0098e4e127a05si1186063ejj.865.2023.07.20.14.15.41; Thu, 20 Jul 2023 14:16:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FmYbKK2M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229990AbjGTUxg (ORCPT + 99 others); Thu, 20 Jul 2023 16:53:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230014AbjGTUx0 (ORCPT ); Thu, 20 Jul 2023 16:53:26 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8F51272A; Thu, 20 Jul 2023 13:53:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689886404; x=1721422404; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+f9djtUanexeaZ5zSzwChI/A5Q553wFyYeJA5WaLw4E=; b=FmYbKK2MARnNXszjMvbc8vPT4LD4RzpbF54NZ1qkZD9MLkc1gSUUfDqN VfNFgeRjFeWi6OPF15esOsQTDKZpglwJje1t+KzYo2NMTbOm9/MllxWj2 a1E3ArrJwTv0KVPQd0kO/hFCPlaB5Nea4iB7njm+0AflBGZHdEJfsbsvv QAtTOgpgQZkbGkSiB/1dLpAQnZz/mUesTm7wpHmWAZ8iLTY8kHyQIpieN DtD1UwnLZ0a1gbibnsv3hoJ0hDcnq96dZl99twIonjouyEu2Kh1mUGxWA m0SXe/G4SGwmRvayUgJv59ux+n16A4xXx/tSBmn6lZsqwWjkDEcEoYGia w==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="370459747" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="370459747" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 13:53:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="971169134" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="971169134" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 20 Jul 2023 13:53:21 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 674FD66C; Thu, 20 Jul 2023 23:53:28 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH v1 6/8] iio: core: Fix issues and style of the comments Date: Thu, 20 Jul 2023 23:53:22 +0300 Message-Id: <20230720205324.58702-7-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> References: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771975755765049923 X-GMAIL-MSGID: 1771975755765049923 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 --- 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 ab9c6db69625..e29772940886 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 Thu Jul 20 20:53:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 123446 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3381106vqt; Thu, 20 Jul 2023 14:08:57 -0700 (PDT) X-Google-Smtp-Source: APBJJlGf3RdrpON/r92XqU2Fd94amfs8FlzMPI7l7zAF1BlTrCCRezpO05Wkaeg8zWWX76lmTDRU X-Received: by 2002:ac2:5dea:0:b0:4fb:89e3:5ac6 with SMTP id z10-20020ac25dea000000b004fb89e35ac6mr2300597lfq.62.1689887336848; Thu, 20 Jul 2023 14:08:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689887336; cv=none; d=google.com; s=arc-20160816; b=VZnQ4JMbC/M5yd9TueFsAZSjp5JwSywYmyQWWMxYr/07HXGdyuLwg4YywHMXLe9Twl NIqbkvazAmlY9xNbxqtU55buQRr3Ad/hRPUishXI5jfhe4jxniX7MILfmknI8O/4jG22 hTZw5r46iY8l1UADNYTPM+Rvz4yg30aGNvAbxG0aTwop+T/UlW//hSKges8UZVdqCADm 5TSBCYnnNtCnpNL3gjuAryP12A1+rzOcuXeS2cXQ7qj2PPQFw9ontb0VDz9nVpZ9hmKB UehudQyxp5h/fhkZOy/i/ecrf6fVV/JZshnok9f07uIzPeHVU5zTVAG6/i8eagu8VV72 QhwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tDdDQvXLVwL44DF6Z8Uhz6K+boW9panSnT08Va3m1YU=; fh=UOk5tC92rpasvTHsS8FNeq1ESsZGN5rcMuNSzha6ebA=; b=thoqYaIlgYkO+4L1PkGExgOaNpYeMXG4OoWHvWEIujY2wW7xhj1EP7In9gA15mEli9 7gJAxK8HOS1KqZAWRqZmyQO7TDag0Le6xu6eO72nrr/PjZXBv4p/445Asa6/NN9nAuTo UImm9jg8JMoJtEILjanNJdxMq5o5zT9wp0P/z720HJZcLFUdiH8TtBdKyaf/nigAovLq OUcQ6f03U682BOr1TPWrsfJpiLpZr1VL2qdn83AoFo8nvchTYrosNlGKK6N7y+Yar/TW On3JfSG2NO/SYm+Q80R/LiCOsZKhS2ak+QhVo6/vl4HYfa6tai/dYmTOOpgoJNKwNWFE Bk7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CraRJbn9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t4-20020aa7d704000000b0051dd50ceaa3si1272999edq.180.2023.07.20.14.08.32; Thu, 20 Jul 2023 14:08:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CraRJbn9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230258AbjGTUxp (ORCPT + 99 others); Thu, 20 Jul 2023 16:53:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230038AbjGTUx1 (ORCPT ); Thu, 20 Jul 2023 16:53:27 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3627271D; Thu, 20 Jul 2023 13:53:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689886405; x=1721422405; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6gvmEe3/mK3F1A2VhT834ZdAXT1htPyMLu4MYEFgzHY=; b=CraRJbn9hXjdDioAnzg2J1C7xgaeA1PGgO9Q/hhAWsG4oIBfziMrQvdE VJpVj/UKpLN34dvMSeSLq+zxX9ibl43ajxvs3ZBsECyqSkW7ElRQQHzvt 8BeCUh+wI/yU7g9GAG70utcCRMInvJfOyx+z8fauHwMe6d+c0ZrjvHjwT vapl8Bb6LbLncQRhIPN/wZPoIbxwBRpkW+1v6X9i0w1BbIPcsKh7BDnLH L477mo04hshLMuBcpSCxrTorgZMZi7ZQlUoZ78a3CkHjV0noAK42B8Ly/ 4QtR/yRPwkdT7kTlQk7mhpb43/k+SSNIlkW65zHgpz2/K8v/HCnVhsZ9W w==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="356846054" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="356846054" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 13:53:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="838273950" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="838273950" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 20 Jul 2023 13:53:23 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 6E85069A; Thu, 20 Jul 2023 23:53:28 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH v1 7/8] iio: core: Move initcalls closer to the respective calls Date: Thu, 20 Jul 2023 23:53:23 +0300 Message-Id: <20230720205324.58702-8-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> References: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771975303908945377 X-GMAIL-MSGID: 1771975303908945377 Move subsys_initcall() and module_exit() closer to the respective calls. Signed-off-by: Andy Shevchenko --- 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 e29772940886..202a1a67ba98 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 Thu Jul 20 20:53:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 123452 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3390200vqt; Thu, 20 Jul 2023 14:30:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlFDrUQruD9lpFHpL4OAEqiVLj9Gng/kY3vGCEoYkH/sSq1z1z7UqXpQF+aWo9kG7XVO3E28 X-Received: by 2002:a17:906:32d2:b0:99b:49a6:952d with SMTP id k18-20020a17090632d200b0099b49a6952dmr3396ejk.65.1689888611332; Thu, 20 Jul 2023 14:30:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689888611; cv=none; d=google.com; s=arc-20160816; b=zpn7TPQ0aImIlQzwjgAeqpn9MmyL6Z1jSBrxW9ibU1DKaxEBhjQmsJGDg9cbROpMt2 u1NrKK/Pimwm/4IOafwkAbCSwVyf9ek9WYmAHWVyBfIQWzUx4vwaPHfmOBoBZ+cycelt aNkU/PTbftavQPCEefE1IQriLjxXXSaOJ4eSy8fkNn/4uw+iktWDJ5vGobwNEe2U6akM 98NSc8Wcqj9J+FANF9fg6WnDONeetq26xRrJYwE8HmqyvZZRSHufUwDqXbrlDboyJwsw 9PtAOlXwwR06i2oYQLQ4MPQ/ewj9natv8iRRh012mnSfkcip22tBtZ1Eis+yY3I9t8nh W5TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cr81hIOtsHS3Y6jPpPdMiv69INk9xFsIBLyCzPQqZoc=; fh=UOk5tC92rpasvTHsS8FNeq1ESsZGN5rcMuNSzha6ebA=; b=ypbVc0soOGfO86LSvHe/RC67AlI+5/24cimOYXOAxyQ4NtPJQX4hdJjC7sp9AECB/F 356soldQFhD4x53cKRr81DEhuKVF7DmFqnlIj1qxlU99Oye29htJCoXp/G0ZXO1M/53+ p4zCFQK+JbL5LLOpvedbA/EQVf0kBxQO45KiOupQ56mZBREi3512BPkijedDDXotkpAm bVg56X+HA3SjhQy1TpzGrD/+QGr7joxgxSmODzTRTOOg14TaCl+52pJJ+8T83x7331GP vlDEDIdgPju+CgWa+R8+fHkbNajrIsY2R6w7nH0EIe+skj6drbe9jIqQey5l7g5yN8vw ap/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Uaetcs5t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m4-20020a170906848400b00992ae4dfc04si1186953ejx.990.2023.07.20.14.29.47; Thu, 20 Jul 2023 14:30:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Uaetcs5t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230012AbjGTUxn (ORCPT + 99 others); Thu, 20 Jul 2023 16:53:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjGTUx1 (ORCPT ); Thu, 20 Jul 2023 16:53:27 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A32C819A6; Thu, 20 Jul 2023 13:53:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689886405; x=1721422405; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i2dOmWbmfP+zv2qAY6T8w+Xkd3L39MYUTAsSIdR8ORM=; b=Uaetcs5tdtI/0wiRPKGPwTla+4DHBBolHw1amKsyPabAMmXT3Jry85vj a0dcTTBFIqo/LM/XR4vZIuC6FKzZMX4qfWntK4d4kLhPBeQ7qAciEkX1k /6FKofzNgNpMZze+FACBo2wYD0ySjYWZ7nveXh932DzBylHCZY/k0Qfqg 1csF/o6hc2PNSWdsKn8STulWtsyDp1gXEkbzTW0WsEZym1LdJ6LFCcX+q kF9Y7Vkm5o8Lb7mCjGkxbCcdCzkboxFHm4C2hrRFyHxplFll8XGTnhBp4 XW4KpfyIMhs2LRmvcZUmZFk0reD/xVH4NvCMM25Tkkyi5qk8zzZ/jc8x7 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="356846050" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="356846050" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2023 13:53:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10777"; a="838273951" X-IronPort-AV: E=Sophos;i="6.01,219,1684825200"; d="scan'208";a="838273951" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 20 Jul 2023 13:53:23 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 75CAA69F; Thu, 20 Jul 2023 23:53:28 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jonathan Cameron , Lars-Peter Clausen Subject: [PATCH v1 8/8] iio: core: Improve indentation in a few places Date: Thu, 20 Jul 2023 23:53:24 +0300 Message-Id: <20230720205324.58702-9-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.40.0.1.gaa8946217a0b In-Reply-To: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> References: <20230720205324.58702-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771976640019355977 X-GMAIL-MSGID: 1771976640019355977 Improve an indentation in a few places to increase readability. Signed-off-by: Andy Shevchenko --- 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 202a1a67ba98..1918da2a70ad 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)