From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EAB4313E30 for ; Mon, 23 Feb 2026 16:31:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771864278; cv=none; b=WZxDQ3k2NSPYbL5PJLGbL60vOAge/iyBaZLV4eBasttoIKi5H2IjcDjVP2my9LptTSDWNu/gs9JDGZAkTq2+XqpxkbGoaA8OLed+HIapndE4ztgZQK31o0iTmAgWBQQG79kITeEfadRgV73sPxEo5RPQiyX7BwY8SLFEbhskhh0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771864278; c=relaxed/simple; bh=AXKL+fcozxp+GpI8pvxD2aSAWc8U1kpa5P0PeJuGNDI=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=GH3IBOjc4OGwmLktteYPbIxXaCoEauXWW/7n6JT7E1xm8EZKY0EYgvOIydaTjBtWAWLA2/s0bG9AqKj0voSCqeWQXEdnhBv+GsKWOGXBY2jMuPp/PA+t7ZRyvyD6ntsfOxBv0h7bXBW4w6dpgyIe3YyOIg2YQ9DSoXV3VPD35BI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=smL3rtHA; arc=none smtp.client-ip=209.85.167.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="smL3rtHA" Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-4639279c7a6so1649544b6e.1 for ; Mon, 23 Feb 2026 08:31:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1771864274; x=1772469074; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=4/WSSubdXWO4v+sW3CLfrhFH7dC9lTt9CrzEJ0rC2GY=; b=smL3rtHAqrJv7TMtk70jhHz42Lvg6NPjZxJZN4zyJBM1WdRwBgk/CVoC5uQQZO8/5v EuAzZrCGx1sCm/aVaczCjnK/tKZOgFsDJkgiyONQK94B3TjFN743RJaS/ZKaND3pCes7 /yvNTIgQFAyzmwDpdvB/HK6nim/Bhgl8Qz7V+72PIRsTDBbQSgNNHEadzL8S9r+zfS8u Xl7NTzJ5IZopHDUxzUuZpuHTQfSzvWf09283FP3R3w0yPx/v9VCoCt6wxsbboDOfPr6j cdrA8tKQzWB9vDZ8spFC7eyFgUP5d3yhx1nGaYQNr8V/8/VnPAv81eMYGCV1EiO9+zkZ IATA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771864274; x=1772469074; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4/WSSubdXWO4v+sW3CLfrhFH7dC9lTt9CrzEJ0rC2GY=; b=SPGeqRSIuYHRTZR+0NVYVTTkILX2Z7CPCdaA0LmmLgFfrx4MoWAnyw9de7kBdeG1/5 2XWgmvlP38rm/IkWyv6o+V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SMTP id 5614622812f47-46446341019mr3593036b6e.33.1771864273966; Mon, 23 Feb 2026 08:31:13 -0800 (PST) Received: from ?IPV6:2600:8803:e7e4:500:e37:2309:3937:4469? ([2600:8803:e7e4:500:e37:2309:3937:4469]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7d52d0725c4sm8168079a34.25.2026.02.23.08.31.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Feb 2026 08:31:13 -0800 (PST) Message-ID: <022c6472-0f7f-4c56-8ba7-7f9690e8a625@baylibre.com> Date: Mon, 23 Feb 2026 10:31:12 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 3/4] iio: adc: ti-ads7950: switch to using guard() notation To: Dmitry Torokhov Cc: Jonathan Cameron , =?UTF-8?Q?Nuno_S=C3=A1?= , Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org References: <20260219022929.3558081-1-dmitry.torokhov@gmail.com> <20260219022929.3558081-4-dmitry.torokhov@gmail.com> <0b9e1c9d-9bee-4fc3-ac19-28d969f65ef2@baylibre.com> Content-Language: en-US From: David Lechner In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2/22/26 3:37 PM, Dmitry Torokhov wrote: > On Sat, Feb 21, 2026 at 11:34:33AM -0600, David Lechner wrote: >> On 2/18/26 8:29 PM, Dmitry Torokhov wrote: >>> + scoped_guard(mutex, &st->slock) { >>> + error = spi_sync(st->spi, &st->ring_msg); >>> + if (error) >>> + break; >> >> I'm not a fan of scoped_guard() because of the hidden for loop in it. >> It hides the fact that the break; is breaking out of that for loop. >> >> It would be more clear/obvious written as: >> >> do { >> guard(mutex)(&st->slock); >> >> ret = spi_sync(st->spi, &st->ring_msg); >> if (ret) >> break; >> >> iio_push_to_buffers_with_timestamp(indio_dev, &st->rx_buf[2], >> iio_get_time_ns(indio_dev)); >> } while (0); > > OK. > > I could also make it > > scoped_guard(mutex, &st->slock) { > ret = spi_sync(st->spi, &st->ring_msg); > if (!ret) > iio_push_to_buffers_with_timestamp(indio_dev, &st->rx_buf[2], > iio_get_time_ns(indio_dev)); > } This is OK. > > to avoid using "break". > > I think you will find that scoped_guard() will gain the foothold in the > kernel so having implementation that does not follow common pattern > might not be the best option. In general, I agree with this idea. In this case, the common pattern unfortunately leads to common bugs. Since we were discussing this, I audited the kernel and found and reported 3 unintentional mistakes with break/continue when scoped_guard() was introduced. And I have caught more in reviews before they made it into the kernel. So I make an exception here to thinking that the common pattern is best. > >>> >>> /* If set as output, return the output */ >>> if (st->gpio_cmd_settings_bitmask & BIT(offset)) { >>> state = st->cmd_settings_bitmask & BIT(offset); >>> - goto out; >>> + return state; >> >> This can return directly instead of using local variable. > > This will require the explicitly normalizing, which we avoided by > introducing "bool state" to begin with... > >>> >>> st->single_tx = TI_ADS7950_GPIO_CMD_SETTINGS(st); >>> - ret = spi_sync(st->spi, &st->scan_single_msg); >>> + error = spi_sync(st->spi, &st->scan_single_msg); >> >> Can just return directly here now. > > I think there is benefit in explicitly calling out the error paths and > explicitly return 0 on success. It removes the doubt whether a function > can return positive value on success. In the IIO subsystem, the direct return is preferred (maintainer and other reviewers frequently request this). > > Thanks. >