Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp964607lqz; Sun, 31 Mar 2024 07:21:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUNJ4bL/vJMoioWw4jSpboVYdO2W8Mi4C7FSyJ/GQzrRKww2Mhv0sm38zLvFDTb0OMZIVUXOPg+fJnGQ8i3Vn3MHt55UpoVUUnEZVJ2Tw== X-Google-Smtp-Source: AGHT+IH27L+12MQm82wIobvyQJ3kcsTc+lpR0MMCcYMIPm/XAYEWapNRKMvzL6zqd0HvaXfP8Xz0 X-Received: by 2002:a17:902:ea12:b0:1df:ff0a:7130 with SMTP id s18-20020a170902ea1200b001dfff0a7130mr9127976plg.33.1711894865564; Sun, 31 Mar 2024 07:21:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711894865; cv=pass; d=google.com; s=arc-20160816; b=0CzUfB22awZsewJViNVWy2QvH8DVCg5NNizw6Z4RVDEMEfIvOsn+9KJ6TnKFdw2N4W HtymCXVpCT7yeLMA3IlSGDTaxYbcbHPlzT2xK5uFyzInAREJUAQmlcy764CHa5VaRbWm ZXTqmu1sqw8pjZA+jrLBfTQrW5nd1sYOXKcV2XebYuCUFOo52HbHSPKsiCkeUyOSB3Rp DDZ3OLGxh2F/AaKmVYr8CsZxv1A+WSqxpvWkyyA/NSGrUTMFQz2xfQ9ncg43pCDI3QOU EA2HKgaic6NlbbuOsfLn72C/QpLBBu1Ir8DxsQZ/38AlpA6pjuS8uQousJDLIvWmI1/4 43SQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=0vuAaX2TGlxLhsPVQSrcog5xSDMSr0P0YNtBNPbNje4=; fh=rgKwEN5iH1sljzklP6KLv/srPCklQChhi6Je1qDo0ig=; b=lg38cLKlI6JC0fY9U+Xi5iESvUUo/mJ7fiD+V+riQGrQGqjiOHb8kuDpo1fbGc5d4F 087NaIIlYrLNdIxTAodAKDFpZa+x45EVrDhNBU/j5wzj5yPrrtjEMat9oOcu56ooZNuJ Z3iWFDHDWUzF1IQmuGCXiVggImvNXedkPt7M5a3kv0aGJHtoHZZt9d2B8/c7sW78Mkh5 Y0KPqbsxlxQC0x5ESLUBoXysB+SVk9U+PaanGRUI82LZPFq49u8Ty7CSSVFolyVS/PTH 4WfL/57whaU0T95PqhXuPmtAylfyVOET2OYNn53yykRABVfvRBTOI/5YWD1z6FsiBfAY gYKw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NYKHmwAP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-126084-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-126084-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id mc8-20020a1709032b0800b001e09e20ccfasi7987564plb.578.2024.03.31.07.21.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Mar 2024 07:21:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-126084-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=NYKHmwAP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-126084-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-126084-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 35459281CB8 for ; Sun, 31 Mar 2024 14:21:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB473145331; Sun, 31 Mar 2024 14:20:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NYKHmwAP" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD932144D2A; Sun, 31 Mar 2024 14:20:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711894856; cv=none; b=h/r98nbj1q+G8lH8n7zYae2C+2YmUAmZAjV83iPxwzWLULchc1zUGKg35Kia/qJykidalxxzSOJu9VWsB2+7Kez2QazY8vRQFUePJt09VgN7plgTcWmqglO2Jhvbch9I8Lpg9QXoU2ZexDK7rl5hODQRPwVkPdYufwndCRYWeaY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711894856; c=relaxed/simple; bh=MhZ+GNwAIgsUTcIkXuF7X0kiB2apEfQgvIGqYvrAc/Y=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=f1hTiyoaVHJbCIUgxf4qlw80U2pBmzILrs7ANe0U6jNHr1BX/CNOykv2cMGW5NQIOmWMrktwqEWrSSOX+ak8XSo/gIdlJcZo9uoVCUnWk8FvIr2973LkEJX5UXK9aMnOmmBvgFg5Q5jrdykWd51IAOIGPZAYdjZGgC2H9/VJ+RA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NYKHmwAP; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C19DBC433F1; Sun, 31 Mar 2024 14:20:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711894856; bh=MhZ+GNwAIgsUTcIkXuF7X0kiB2apEfQgvIGqYvrAc/Y=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NYKHmwAPHxH908yfjReJj3s5LqlkFu+hqeyf6R3JKvUdwJ2CxXP7G65iuUi98d5YE jGuAeo74BElsHwjXvbUi0r4VNa0h1JXBXSnauW2Xmb1dxLXVVqz997lKns1jG+/WvB kOiHNL/OHMjOcDr6uYlFYx/ym10GPbiPlbdiNtznO72r5jMj1+klBA3Fn2SREW1odh qL8k9KboyXDlnUDBXpl2OXQifFiV3OeKnAZ5qj1GVR6nQa0Xmd9GCQiWrKqjQwcRVk Dk3ZgLZBqjSR1vri/hGvOnhoJChXxCjExYp8hn7C48tVwElLLYH8gYzDJDjUQgRwp8 Mr8t4UnXpcCgQ== Date: Sun, 31 Mar 2024 15:20:42 +0100 From: Jonathan Cameron To: Jonathan Cameron Cc: Dominique Martinet , David Lechner , Krzysztof Kozlowski , Syunya Ohshio , Guido =?UTF-8?B?R8O8bnRoZXI=?= , Lars-Peter Clausen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , , , Subject: Re: [PATCH] iio: industrialio-core: look for aliases to request device index Message-ID: <20240331152042.394b4289@jic23-huawei> In-Reply-To: <20240318122953.000013f3@Huawei.com> References: <20240228051254.3988329-1-dominique.martinet@atmark-techno.com> <7f03bb12-0976-4cb7-9ca9-4e4e28170bdd@linaro.org> <20240228142441.00002a79@Huawei.com> <20240318122953.000013f3@Huawei.com> X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 18 Mar 2024 12:29:53 +0000 Jonathan Cameron wrote: > On Mon, 18 Mar 2024 11:15:36 +0900 > Dominique Martinet wrote: > > > David Lechner wrote on Fri, Mar 15, 2024 at 10:53:36AM -0500: > > > How about using udev rules to create symlinks for each device based on > > > the label attribute? No changes to the kernel are needed. > > > > Right, it's definitely possible to make symlinks for each "device" -- my > > patch comment links to such an udev script "solution": > > https://git.toradex.com/cgit/meta-toradex-bsp-common.git/tree/recipes-core/udev/files/verdin-imx8mm/toradex-adc.sh?h=kirkstone-6.x.y > > (the script is launched by udev here: > > https://git.toradex.com/cgit/meta-toradex-bsp-common.git/tree/recipes-core/udev/files/verdin-imx8mm/99-toradex.rules > > ) > > > > My conceptual problem with this is that this makes symlinks in /dev to > > files in /sys and it feels like we're crossing boundaries. > > As far as I can tell there is no way for userspace to create arbitrary > > symlinks in /sys, so I think we could have an interface more > > user-friendly by allowing paths to be static for users with multiple > > devices. > > (I guess that's a weak argument given e.g. disks etc will also have an > > unreliable name in /sys in the general case, but simple programs don't > > interact with them in /sys and can use stable links in /dev so my > > expectations here aren't quite the same) > > > > > > Ultimately, the problem might run deeper in that we're having userspace > > interact with the device through /sys and not the /dev char dev... As > > far as I could see /dev/iio:deviceX only allows reading buffered values > > and doesn't have any ioctl or other way of reading immediate values as > > is possible in /sys though, so that'd require quite a bit of work to > > duplicate the interface there... > > Don't. The sysfs interface as only control is entirely intentional and > we do not want IOCTL based duplication. > > Just addressing this bit as I'm still a bit snowed under to think about this > more generally. > Hi, got back to this finally... So the problems compared to other 'alias' users is that IIO is a bit more complex than for example LEDs. A single DT node/compatible (or equivalent) can result in a 1+ IIO devices and 1+ triggers. Triggers can also be instantiated via configfs (technically devices can as well but we can ignore that). Any alias scheme needs to work for all these options. To my mind that makes it a userspace problem, not something the kernel can deal with in generic enough way. I think that all IIO devices have ways to stability identify them (label, or parent devices) There is an approximate equivalent of DT alias entries in SMBIOS but I suspect not all ACPI platforms will provide that (it's typically used for stable disk / network device naming on complex servers). So I've messed around a bit and can think of various possible options to make this simpler. 1) Use a tmpfs mount and link from that. Now we 'could' put an alias directory somewhere under /sys/bus/iio/ that is a mount point created via sysfs_create_mount_point() - I abused the /sys/kernel/debug directory to test this (unmounted debugfs and mounted a tmpfs). That would provide somewhere in sysfs that allows suitable links. However, this is unusual so likely to be controversial. 2) Alternatively the relevant platform could create one of these somewhere outside of sysfs and use udev rules to create the links. 3) Stick to the oddity of doing it under /dev/ 4) Access the things in the first place via more stable paths? /sys/bus/i2c/devices/i2c-0/0-0008/iio\:device?/ etc Relying on the alias support for i2c bus numbering to make that stable should work and if you are sure there will only be one entry (most devices) that matches the wild card, should be easy enough to use in scripts. My personal preference is this last option. Basically if you want stable paths don't use /sys/bus/iio/devices/ to get them. Jonathan