From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f178.google.com (mail-oi1-f178.google.com [209.85.167.178]) (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 AC0D337F119 for ; Mon, 9 Feb 2026 15:28:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770650904; cv=none; b=ROO6pUBSEHyZNBrPFgmrg0dshJy3VYdWpAE4lE6nIVsMpebw7iNTwR0ELS63NaVWUevWUt/JeqZm52eR0j8c6QnJtTT21RF3yCkpytIsp6gdNobZHD2Vxzq2k63nr4O9t8Ms3YmLMoNN63nEGqE3mCSX9411c0Mhl9VqAp5m0X8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770650904; c=relaxed/simple; bh=DTkjd0tNFRfFZrVjzA71TMao0DYCnAq9XUrVmaOJWbo=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type; b=bGPjjOaffbQNo04hQg3FYsxOB/OZXVuYhAMDflo8Zk5okbncMZNt4DBzt8/UWsAqMNaiVHyUsU1RBPnM2VI7ekjrmqajBHfvCAvBMFyHHlNbQBc/829eezeJuFQk2PHyWonzUQnbYqRdW9vgS7NWsDsoSaFvpFpTF66FB7wOvY8= 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=n7IhtTW3; arc=none smtp.client-ip=209.85.167.178 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="n7IhtTW3" Received: by mail-oi1-f178.google.com with SMTP id 5614622812f47-45f0c1f1b54so2776139b6e.1 for ; Mon, 09 Feb 2026 07:28:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1770650902; x=1771255702; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=9KZTHcq5eFjr9M/3mrNSgDFRjuluDN92D/wtKMFTk4A=; b=n7IhtTW3STJNle7++iMfAeuQvnynGeL+/R7BZBFHavWmez6as9nYPTkQqxk3ACnkPo ccUBvAKe57b4axD876mXMorFGSBF84VrwIZhaUenYvOsQZxNekL/P853sJs+FaLJkVmU q+YFVxK+Iyz/wIjp23w+6rPENtHk0765gImweDHLggXBeY63009AJEgiICdvRntqGohq bdShYlnO2xVLvVSb0HEcMDf5Q58xJwBnFWWVJVhyeS03miv6nCUVprwAAfUgzebyr9ja 7J/HCpKDNP6bSfrBddNhfzze3x/eXyNpaSPx2gQ+0fydPCZyryR9fylNliNN1EZGZxnQ GAIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770650902; x=1771255702; h=content-transfer-encoding:in-reply-to:from:content-language :references: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=9KZTHcq5eFjr9M/3mrNSgDFRjuluDN92D/wtKMFTk4A=; b=kZcuPiXvwYN0WX6aJaU7g5EFPvNoKlMaJgTrsxagHFKCi8ZKf81S0rG18rza/DgZki 2ejYwfLLKqD7yq862lTixpfvtSDFPuHAoyIwx54CIONHebESrYx6R81n2HcbHHAtbIgx sdpgN8zVbPu/xtdkcVz+RM36kLBBmfI1LgWzZky8UoLN6ZCW94IYdASUjDF1n/L5mUtu roB85KS79moltNfbjV5Ak8R5XNWYmOWRNHkFKPZC5x+Su9S1F32j+9kBfBvGfQHRgSwJ OhzH8ZjqNEYvx8ijr1V4sb/u63DmtcxGjjKCzpoZeN7zjN4P8oqKGJ201oMzywzms1kR fZ/w== X-Forwarded-Encrypted: i=1; AJvYcCX8d3QQ5UdO7Cd+cH8ZNLQ+33aWqqIHcrOiRRPm9i+HJZN22KFsMGU3m+j3f33gXaH/F7du9flgHINV7Qo=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6oBZbNiF/MWsiPiBwfkEq2pbZtrbKbJhC8+JYFu6G7cUtvyQW KdWKqUgo2JlVFLKjipITPsWuUfIOqNQ5jLrZOi9X7WeYfhyiwF4yzQUkwyuEq9lDJxc= X-Gm-Gg: AZuq6aIt9WVB7vvX5X9uYlLSG/WktoywDG8Yubeun9k1bHn5ld6Wl8NQuRFBKhlXP21 t0lTo+835XYfHze4WWQUBYSJUk96+eaqC5nIg0HKkKM6fd/vfO6wcfG3P3/PcpGNdrnSigfC/Zo Cb866vtKnxl9Bm7NN2YLuxg2nzIRjbpEU3onhc/U/aUKZBWN3tECnz+Ich24s8IqI0TnUU/3K/C 5p14HZpqHagcrWflF4QrZQ5bYs69TRl132GHeJrhY4skj/mFxsazZkssUO3vUPGRWC2nu+nNsTl 49cAlJ2zl1Y2iKD0rt4MiT+oZiK6bUinUM1kwgO19Bnbqs3XhkOZpnNeCDgpZVJJHM8/FTh/ZAE A1NuKj4oRcyuKe68onFP4AQf1KwnvPyyQ1WwVLIWGz5+bRA0/8Z+V0csm7QDJEHq6O4BlW5TE8n 9Vup1PLRZ41mQLmhaliGJu0ZqaSTMHe3LtYykpBmfzcIQP2dQ17J1bUr6XhIk4 X-Received: by 2002:a05:6808:c198:b0:45e:aba8:124e with SMTP id 5614622812f47-462fcf53c0bmr5694687b6e.23.1770650902598; Mon, 09 Feb 2026 07:28:22 -0800 (PST) Received: from ?IPV6:2600:8803:e7e4:500:cee0:eb0c:b683:ad1d? ([2600:8803:e7e4:500:cee0:eb0c:b683:ad1d]) by smtp.gmail.com with ESMTPSA id 5614622812f47-462feb0d786sm6700789b6e.11.2026.02.09.07.28.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Feb 2026 07:28:22 -0800 (PST) Message-ID: Date: Mon, 9 Feb 2026 09:28:21 -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 2/4] iio: backend: add devm_iio_backend_get_by_index() To: =?UTF-8?Q?Nuno_S=C3=A1?= , Antoniu Miclaus , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , =?UTF-8?Q?Nuno_S=C3=A1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Olivier Moysan , Mark Brown , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org References: <550323d752213f177b7673bdd42e667f1d2228cb.1770393792.git.antoniu.miclaus@analog.com> Content-Language: en-US From: David Lechner In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 2/8/26 3:24 AM, Nuno Sá wrote: > On Fri, 2026-02-06 at 18:07 +0200, Antoniu Miclaus wrote: >> Add a new function to get an IIO backend by its index in the >> io-backends device tree property. This is useful for multi-channel >> devices that have multiple backends, where looking up by index is >> more straightforward than using named backends. >> >> The new function directly uses the index to find the backend reference >> in the io-backends property, avoiding the need for io-backend-names. >> >> Signed-off-by: Antoniu Miclaus >> --- >>  drivers/iio/industrialio-backend.c | 51 ++++++++++++++++++++++++++++++ >>  include/linux/iio/backend.h        |  2 ++ >>  2 files changed, 53 insertions(+) >> >> diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio- >> backend.c >> index 447b694d6d5f..3b692d48481e 100644 >> --- a/drivers/iio/industrialio-backend.c >> +++ b/drivers/iio/industrialio-backend.c >> @@ -1008,6 +1008,57 @@ struct iio_backend *devm_iio_backend_get(struct device *dev, >> const char *name) >>  } >>  EXPORT_SYMBOL_NS_GPL(devm_iio_backend_get, "IIO_BACKEND"); >>   >> +static struct iio_backend * >> +__devm_iio_backend_fwnode_get_by_index(struct device *dev, >> +        struct fwnode_handle *fwnode, >> +        unsigned int index) >> +{ >> + struct fwnode_handle *fwnode_back; >> + struct iio_backend *back; >> + int ret; >> + >> + fwnode_back = fwnode_find_reference(fwnode, "io-backends", index); >> + if (IS_ERR(fwnode_back)) >> + return dev_err_cast_probe(dev, fwnode_back, >> +   "Cannot get Firmware reference\n"); >> + >> + guard(mutex)(&iio_back_lock); >> + list_for_each_entry(back, &iio_back_list, entry) { >> + if (!device_match_fwnode(back->dev, fwnode_back)) >> + continue; >> + >> + fwnode_handle_put(fwnode_back); >> + ret = __devm_iio_backend_get(dev, back); >> + if (ret) >> + return ERR_PTR(ret); >> + >> + back->idx = index; >> + >> + return back; >> + } >> + >> + fwnode_handle_put(fwnode_back); >> + return ERR_PTR(-EPROBE_DEFER); >> +} > > I believe we don't necessarily need this. Why can't we use io-backend-names? I get > that in here we just want something matching the number of channels we have so giving > names is probably does not add much added value. But still, I would prefer t have > more simplicity in the API and it should be fairly easy for the frontend to use the > names argument. > > _ Nuno Sá > IMHO, using names in this case would just be annoying because we would have to sprintf the string to add the index to the string. And also have to spend time coming up with more complex DT bindings. Using the index seems much simpler. If you really feel strongly about it though, maybe we could make a devm_iio_backend_fwnode_get_fmt() function instead that handles the sprintf() part so that we only have to write that once?