From patchwork Thu Mar 31 23:06:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 12797783 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 ED887C433EF for ; Thu, 31 Mar 2022 23:07:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242742AbiCaXJG (ORCPT ); Thu, 31 Mar 2022 19:09:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242262AbiCaXJF (ORCPT ); Thu, 31 Mar 2022 19:09:05 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6F05241A13; Thu, 31 Mar 2022 16:07:17 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id g22so1018459edz.2; Thu, 31 Mar 2022 16:07:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Gwff2ScMyduRFsgNLSOrbaYErL2LHR4WqzSPtFakqCI=; b=E4dRxHk3X5Xz6uhDp52u6jrJvE/XjTHOkNGNPYHzoNyNyghBE6nTVogfQ8NX+WJRF+ t250rCKrgxpbGxzg+KY3hCGGnyGjZW2o0WU8L5QRafo1cSwGkkZG2NmusPL+7kFSM836 8mgGNyoSS3NL003Il3/2o6f6brvr7F5JEWStaxaRFe/ZPx1dPwTy/JQiJAQutw9xJoYp EBB5mHEYQvZ6GtHlE1eU3j7oIMutmWsUCelULppAPxeHaaErMOhmabxp1MtFlGFzehh9 akogZ7C7SNqduYGp7+ECJcENz8e8I/rXSycU1PohiljVQPp/hwv8AKQelfnjOx5bKHdb Vk8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Gwff2ScMyduRFsgNLSOrbaYErL2LHR4WqzSPtFakqCI=; b=D2DHqVMHqq3oWjQCXrFjey82bZusKAc4DjlO3+tgUBZm+vN8qRwHnh4qZXg4kCodVL VpNrV+QpDcRCtFW3F0+GZZwJYBAg0d449cnCwcYXmjESQN0qs1Gx3P6wj+1iKxPXgqm7 3AOwh49tND5PdJjOKYQSQhFz5OnyY+JUhc3vf4OdOXYNLxxS+BHYB3KrXOzE0wU49IIv PqmGCGdCUUPtzzlhl1XN1YHtGy6VcFez+jCWMWDvoRnFDXEyD7WUlMbMKVX6l8DDWqJt FUUlCWwVDvBrFgKxpNzRWJifJbhkUvtR7QgX05HxCq3XtySo3vgL1Vh5qX4+kPgtYc6H bPRw== X-Gm-Message-State: AOAM530cTS2cv+ksk1hmeIBLGtdb6yRvwrk8gKocb9sy1vpdyJiG/qbC 4Azle9G1l7/mWbH9l4j/ujo= X-Google-Smtp-Source: ABdhPJycWqtrvPwUIXmTfiMnkiB4sefH2ALh1PxluMvc+KyauHkt1vUUhyB2uVulSaxCw+9lqe4GTA== X-Received: by 2002:a05:6402:2219:b0:418:ed4e:f999 with SMTP id cq25-20020a056402221900b00418ed4ef999mr18450252edb.121.1648768036169; Thu, 31 Mar 2022 16:07:16 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id p12-20020a17090635cc00b006e055c9c91esm297131ejb.101.2022.03.31.16.07.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 16:07:15 -0700 (PDT) From: Jakob Koschel To: Jonathan Cameron Cc: Lars-Peter Clausen , Dan Carpenter , Jakob Koschel , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH 1/3] iio: buffer: remove usage of list iterator variable for list_for_each_entry_continue_reverse() Date: Fri, 1 Apr 2022 01:06:30 +0200 Message-Id: <20220331230632.957634-1-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org In preparation to limit the scope of the list iterator variable to the list traversal loop, use a dedicated pointer to iterate through the list [1]. Since that variable should not be used past the loop iteration, a separate variable is used to 'remember the current location within the loop'. To either continue iterating from that position or start a new iteration (if the previous iteration was complete) list_prepare_entry() is used. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel Reviewed-by: Nuno Sá --- drivers/iio/industrialio-buffer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) base-commit: f82da161ea75dc4db21b2499e4b1facd36dab275 -- 2.25.1 diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index 208b5193c621..151a77c2affd 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -1059,7 +1059,7 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, struct iio_device_config *config) { struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev); - struct iio_buffer *buffer; + struct iio_buffer *buffer, *tmp = NULL; int ret; indio_dev->active_scan_mask = config->scan_mask; @@ -1097,8 +1097,10 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { ret = iio_buffer_enable(buffer, indio_dev); - if (ret) + if (ret) { + tmp = buffer; goto err_disable_buffers; + } } if (indio_dev->currentmode == INDIO_BUFFER_TRIGGERED) { @@ -1125,6 +1127,7 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, indio_dev->pollfunc); } err_disable_buffers: + buffer = list_prepare_entry(tmp, &iio_dev_opaque->buffer_list, buffer_list); list_for_each_entry_continue_reverse(buffer, &iio_dev_opaque->buffer_list, buffer_list) iio_buffer_disable(buffer, indio_dev); From patchwork Thu Mar 31 23:06:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 12797784 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 5D2D0C433FE for ; Thu, 31 Mar 2022 23:07:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242763AbiCaXJH (ORCPT ); Thu, 31 Mar 2022 19:09:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242752AbiCaXJG (ORCPT ); Thu, 31 Mar 2022 19:09:06 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74484241A0B; Thu, 31 Mar 2022 16:07:18 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id r13so2341321ejd.5; Thu, 31 Mar 2022 16:07:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Tq6felZrVZ9OJWr5Zlb/qFgwlSaptzfYLpBsT8+rZ38=; b=VVN9eOsHfWaNm51McvRFnSTZvSAdYphiV2X9W8Nh1okB64o6u5Ld54RYqzI6F1XMjg lW47piFIJURUfOzCnYPMdqtGqDYUchTMV48l+RB2X0CNa/UW6nkaIfgFoi3PQ61k+B9q 9+qAG3U/7eRB/Syi1WdwM7jkrZ0ZIkPcSGfOCiRmkyjcKo50ZsQCZGnOBaYIztQVzfFE H25AOVZF/zw8HasSesB2/H6juHQ+gSaxiWMrPkxMQUyQZbUplMg3p7Gy4Z7K6JDrAKL9 XSnOTVud7AJBUv6MEh1zDn1c9iTYLVUG1C//Pa9WqAhNVIro/5yLJzG2fzUrEPV+ueM6 qbvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Tq6felZrVZ9OJWr5Zlb/qFgwlSaptzfYLpBsT8+rZ38=; b=A9o/Q+vPWsAFHbLtVN0fqJBqrj9epbwIODnL+EUfns8DuRqJL1o78iBDxiUBsr4Bz+ CWVk5pMNHyGjKQ2ZW2Mx2yddQ0F4BlweigD3WhKnSfGrjGBNxoIX/f3+VWc9uHbi0p54 tGPIztmmLRlfeHlMGxYHFvdV5Gnkk4OrJ4OInvts5HvSw8x+kkZa6/liFCl8Z2h4wnYH MITuQ4yrlv1QJIUNNFY1uAdax1irgiMYZD9qrbRFs/SlOFYYIZv2UeTwQvnTOZegvy44 JGpzmhhoC5qOwMbdWk5RjO80u4JwBJyUE0HWXxZ8PXMsgDT/ROn9LDQwiI5kfrST66gt doJg== X-Gm-Message-State: AOAM531ThE0EDChKNVD2VNSQSvf+JFn7JkXcnEjG3RZCc2LRbD4yub0h h67ocSDihzbcK6lW/6mATXc= X-Google-Smtp-Source: ABdhPJwjUlMDCoWE9kl9gNy0jVgXn+nwjD8zZMvHsRGS5fR8q+vsfK7b8lcQbMyjTPRvlpQAQ1LYIQ== X-Received: by 2002:a17:907:3e99:b0:6db:6c1c:d9d9 with SMTP id hs25-20020a1709073e9900b006db6c1cd9d9mr6835447ejc.688.1648768037035; Thu, 31 Mar 2022 16:07:17 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id p12-20020a17090635cc00b006e055c9c91esm297131ejb.101.2022.03.31.16.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 16:07:16 -0700 (PDT) From: Jakob Koschel To: Jonathan Cameron Cc: Lars-Peter Clausen , Dan Carpenter , Jakob Koschel , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH 2/3] iio: ssp_sensors: replace usage of found with dedicated list iterator variable Date: Fri, 1 Apr 2022 01:06:31 +0200 Message-Id: <20220331230632.957634-2-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220331230632.957634-1-jakobkoschel@gmail.com> References: <20220331230632.957634-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable instead of a found boolean [1]. This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel Reviewed-by: Nuno Sá --- drivers/iio/common/ssp_sensors/ssp_spi.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/iio/common/ssp_sensors/ssp_spi.c b/drivers/iio/common/ssp_sensors/ssp_spi.c index 769bd9280524..f32b04b63ea1 100644 --- a/drivers/iio/common/ssp_sensors/ssp_spi.c +++ b/drivers/iio/common/ssp_sensors/ssp_spi.c @@ -331,12 +331,11 @@ static int ssp_parse_dataframe(struct ssp_data *data, char *dataframe, int len) /* threaded irq */ int ssp_irq_msg(struct ssp_data *data) { - bool found = false; char *buffer; u8 msg_type; int ret; u16 length, msg_options; - struct ssp_msg *msg, *n; + struct ssp_msg *msg = NULL, *iter, *n; ret = spi_read(data->spi, data->header_buffer, SSP_HEADER_BUFFER_SIZE); if (ret < 0) { @@ -362,15 +361,15 @@ int ssp_irq_msg(struct ssp_data *data) * received with no order */ mutex_lock(&data->pending_lock); - list_for_each_entry_safe(msg, n, &data->pending_list, list) { - if (msg->options == msg_options) { - list_del(&msg->list); - found = true; + list_for_each_entry_safe(iter, n, &data->pending_list, list) { + if (iter->options == msg_options) { + list_del(&iter->list); + msg = iter; break; } } - if (!found) { + if (!msg) { /* * here can be implemented dead messages handling * but the slave should not send such ones - it is to From patchwork Thu Mar 31 23:06:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jakob Koschel X-Patchwork-Id: 12797785 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 C47E1C4332F for ; Thu, 31 Mar 2022 23:07:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242771AbiCaXJI (ORCPT ); Thu, 31 Mar 2022 19:09:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242767AbiCaXJH (ORCPT ); Thu, 31 Mar 2022 19:09:07 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32115241A13; Thu, 31 Mar 2022 16:07:19 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id c10so2244011ejs.13; Thu, 31 Mar 2022 16:07:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Dbd+FeFljOdDtTjz0SE9OURXlnjXbAIwzSzKI/SK8Hs=; b=oPmqCMSQjmk62BS1YZ2/0YxmoKih7cVsZOjbV01H/cpzCZXanTD3d+oAcdX2qAT8Oo OJ6zmB/cbMgqWwCjTZX9YHglYfvNyKkXL0dBQkpvJ6bOSJwen1FY9tRttbCFwqBF6TzO RNlET5odbw5xuBYazYYMj+FmmmY80K9h7Ow3n/vLJdKOBgKwTKSfoRwHd+yrX7i06b4H kHN3WV21ODDDom6U3LE578k/SU6cdEFz8PPfbV9MG3nFI9F3iaf96ynZYO5hLR//USCT MEBACGkXBQ+aaKwzYBllBhXZ5d97CXEhh/L0cJjrvxe1Y7Hn1Uod9pfnWatBNNsyDhCY LMTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Dbd+FeFljOdDtTjz0SE9OURXlnjXbAIwzSzKI/SK8Hs=; b=pvLXYK9V8cE20/5OJHtbSZg86WHYzVjhMt6b7SCbmhuhL/1ojAARojB5F+QFnXhSxu JcJ6Z8yfLoNFVikq5L/ZieHF9S56qdz6N6RPGACH3fVf2R3GwwyboYKvusPgzMKW533W M71LvSdisDSi1PiNLiY+EomSp6YOzJjT1XDsO11zrZm9mzHVV7X72p6VMTF331Fr9Ewo KkUa/DF5/VCAJkenS3o92dsP9fgVula12/bXvDtUczZ/hH1qq2fRt+3kS1ZbZQUhnvYv OxA6b+oB/R6VwK0oN9sPNioEtcXmZM9En1Zib4hL/eWugUs6JmxgGTlEEasfTx5HdfO1 wMZA== X-Gm-Message-State: AOAM533Wpo7+f58m/kIE7+LKhGo+DGJACP5z9caSP5Tj3ODlN2BTt/dZ q6jfhYNb2tzgBPAwdKKX4rU= X-Google-Smtp-Source: ABdhPJyrF6FjKgnMDnGC1tbIqIH9Sh1hVWToOj0/1UDT7ZU9e3El36RtthXnxRjHHqBDctFTTptAsQ== X-Received: by 2002:a17:906:2a85:b0:6ce:36bd:bcd9 with SMTP id l5-20020a1709062a8500b006ce36bdbcd9mr6819245eje.318.1648768037754; Thu, 31 Mar 2022 16:07:17 -0700 (PDT) Received: from localhost.localdomain (i130160.upc-i.chello.nl. [62.195.130.160]) by smtp.googlemail.com with ESMTPSA id p12-20020a17090635cc00b006e055c9c91esm297131ejb.101.2022.03.31.16.07.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Mar 2022 16:07:17 -0700 (PDT) From: Jakob Koschel To: Jonathan Cameron Cc: Lars-Peter Clausen , Dan Carpenter , Jakob Koschel , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Mike Rapoport , "Brian Johannesmeyer" , Cristiano Giuffrida , "Bos, H.J." Subject: [PATCH 3/3] iio: sysfs-trigger: replace usage of found with dedicated list iterator variable Date: Fri, 1 Apr 2022 01:06:32 +0200 Message-Id: <20220331230632.957634-3-jakobkoschel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220331230632.957634-1-jakobkoschel@gmail.com> References: <20220331230632.957634-1-jakobkoschel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org To move the list iterator variable into the list_for_each_entry_*() macro in the future it should be avoided to use the list iterator variable after the loop body. To *never* use the list iterator variable after the loop it was concluded to use a separate iterator variable instead of a found boolean [1]. This removes the need to use a found variable and simply checking if the variable was set, can determine if the break/goto was hit. Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1] Signed-off-by: Jakob Koschel Reviewed-by: Nuno Sá --- drivers/iio/trigger/iio-trig-sysfs.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/iio/trigger/iio-trig-sysfs.c b/drivers/iio/trigger/iio-trig-sysfs.c index 2a4b75897910..f1a8704e6cc1 100644 --- a/drivers/iio/trigger/iio-trig-sysfs.c +++ b/drivers/iio/trigger/iio-trig-sysfs.c @@ -176,16 +176,15 @@ static int iio_sysfs_trigger_probe(int id) static int iio_sysfs_trigger_remove(int id) { - bool foundit = false; - struct iio_sysfs_trig *t; + struct iio_sysfs_trig *t = NULL, *iter; mutex_lock(&iio_sysfs_trig_list_mut); - list_for_each_entry(t, &iio_sysfs_trig_list, l) - if (id == t->id) { - foundit = true; + list_for_each_entry(iter, &iio_sysfs_trig_list, l) + if (id == iter->id) { + t = iter; break; } - if (!foundit) { + if (!t) { mutex_unlock(&iio_sysfs_trig_list_mut); return -EINVAL; }