From nobody Tue Apr 7 02:59:24 2026 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 D727FBA21 for ; Mon, 16 Mar 2026 13:52:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773669148; cv=none; b=Y55IL7AJSp0sE0qKghCQ7gyIBhXUhU2Pn9RJYsSx+Q9Fz/Ga5Bh6t/0DxJutep0Enbp5O5X8MNmZ+Ao8p0B9GGVMwnINI96bU9lHgg9cGsN9CNagLO9hU0ut2FzpkmU8194uR+MnURGwaKlUzd9Lt/IheGJUwAHP++xNhrWBCek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773669148; c=relaxed/simple; bh=ou7reqT/wcXjiO1qmnl2tBuKhN8/ZKlH3/7gf6NTwIk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=rfwoTBkLMaOzHyZ86Lpv+8VkomMCGwtJa9s59QQ52tsr9Kkw2/x1Pxqu8gTbGAZbiKVfv21tLpzGM3svSqrsoqjeQ4bvI3eCqqdMLE9hsGTGoBLaVRQcvD0LrDIsJydgNjLayhw6f4s0lvlMn4gNRUQQE6L8vaeZ0ZRfH8OJ1sg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=O/fLv8Zq; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=GuRYIiAy; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="O/fLv8Zq"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="GuRYIiAy" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 62GDdtI5041587 for ; Mon, 16 Mar 2026 13:52:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=FS95DuGwePcn08gkmGxg19 H9i98Hxg0lazfyqBhiI0c=; b=O/fLv8Zq6ise1gJ0eNAlShhniCueXU+zt92UXS bzi/UkZivRExwVytghfZAS05EQNVKphNNCDn5I8CyO8oYkCKiRdGSfQKMMN1znYy +BuVKTUpzvJOqtZwokx7EmJibINJQLrsQ+qv5l5Ngsk/LxmebnYABF6ckcZ4kKSn C8Ol5aq76q04++DCf+Rr4hFkTAxLkhc6+nZtcgAgGgIBosgxPGn25cbAIQi3DvUF 9x1RGT3At7iNV7dIorBAUqrTazyHAz9bstVwRpciDmXsusd2LEBtCU6BDMdF9Aj/ kmKfbBv8Oj9qAu+Lv2/jwemxt4RsMX89WggQZnKWWfQR8VNQ== Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4cxdt81d0q-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Mon, 16 Mar 2026 13:52:25 +0000 (GMT) Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-8cd773dd39bso3621110485a.2 for ; Mon, 16 Mar 2026 06:52:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1773669145; x=1774273945; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=FS95DuGwePcn08gkmGxg19H9i98Hxg0lazfyqBhiI0c=; b=GuRYIiAy9QEysR39fsHh9aPCRXuS87eTKE76DsW5G7bLsUT3clrqYdicOk0Jx0WCgP yCy8ArRx58s+s0V1dTZ8EvNb+Pr8WtrpNSc5L/PpjcaEQycs6ZnVqR0cfDuXJ6Q/0EL7 Mog6Og98F/sJBNthdGqFWprR06eoQwKq1jCp4QUCV8FjS1xBIPOQpHlVkeqP2oowLPxd Pnn1fe0Y2S+DrjDc+F+6pkXXHjCaMEt7pupSptZ2i+PvxgePylYg5Cc4TijceUdWnW+2 R1HcpgYh2W7kIFNKf4n5Q8tgotetbivkwDRzGDcA4fvE3mwU+GmXSFAC9nNwN0RK07Qg Dxdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773669145; x=1774273945; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FS95DuGwePcn08gkmGxg19H9i98Hxg0lazfyqBhiI0c=; b=WtuW8fixEEJuVymLkAde1j626CR9Z2QPxJcitkk1IHqUWSDZXNugYfTNuxqPErJqo7 +9Himf9QkYVMJwYQMZZEaImJYMgdKN9QYouFsVg3ESF7y75SHSA8UyeTYSlnn4p1VOF4 lMSaVbW9JwirZaLA4YOBYPCKo/7Gt2l81E0jnJK+4YSgyBhhCKWYdjo+FhwLGB3Rz+iO F6n26w527fPx1ElY3t1L4xJY4elOcn/+xAktv6n79ZSeNPuXqlAh1QWa8m9byoEKkonh TNw9/KO5nenF6Lt7qfgqAcXfLUTEyLN2SqSsqQykn4FrFew2sfNvqrGaqiD7FAXlo1Rl mICg== X-Forwarded-Encrypted: i=1; AJvYcCVrnSDWdfE6Bgbcrz8OPYIUIglWPeKrEBGVmr2+tHP2LTcYmNaKmZzYIfgpDFN07aWHlb3kJo8y3hp4U8U=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6OlM0FuNN/U3P8xPsn+CURxjIkN2bOPXrPuNXkwBUThfI5rEz Pj5KPE0n7nJjcXA8K/aAN34fBpuB8dEzBTij/k7BhxRtyxE7mTf4wlAOba/N3j8wgnS1Fh51/hn Q+1SSU0SPmMXe4t4GFXzvE+9Lq2tT/74zsoYacriyJMA/KgSis2OvaYIG9e9ccyD9tBRYIwAevi I= X-Gm-Gg: ATEYQzw8jOubk2QGcN8BSqO4biSl0vfx+dCeXUqF8ZO7x6Ri7VJXJubNpLQLkvBfbjn JVuBTgN5p9jKX/N7hwepKZNRSH6HTC++4kH1QzOwelSVEJk3VN/1lK615+GzTI1HItqx+Meaqxe KDGGdhoRpE6RyAPjscMK/BEiWo/8O7bo+flvxLmqxW7uY16lEBMlcP19CHHEIQ0Ax98oZeVM1Og jM14C7eN1v1XazetInrm1Dz5G7XUXDVY7YSPsVEvqLahvUq0O8shqPa3Ab/+3SeGjbBQ14Dut6E 3cOvQaZlXyFUqPuS1n4ziAOJv1pRern3RvBfV8cWnyb0u2HmN5nm+K6XYc7zPGh517hQsQ2kkPF Hq/TDrGyOSvxV/UPXss00DOxRSPs+M0I+VFMojNA3FfRIHkr2n9k= X-Received: by 2002:a05:620a:40d3:b0:8cd:8e8c:2054 with SMTP id af79cd13be357-8cdb5b5f310mr1712208085a.47.1773669145042; Mon, 16 Mar 2026 06:52:25 -0700 (PDT) X-Received: by 2002:a05:620a:40d3:b0:8cd:8e8c:2054 with SMTP id af79cd13be357-8cdb5b5f310mr1712204885a.47.1773669144529; Mon, 16 Mar 2026 06:52:24 -0700 (PDT) Received: from brgl-qcom.local ([2a01:cb1d:dc:7e00:45fe:3ba6:f90:d951]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4854b66dedfsm437147575e9.12.2026.03.16.06.52.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2026 06:52:23 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 16 Mar 2026 14:52:17 +0100 Subject: [PATCH] gpio: shared: call gpio_chip::of_xlate() if set 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260316-gpio-shared-xlate-v1-1-0ce07a1362d2@oss.qualcomm.com> X-B4-Tracking: v=1; b=H4sIABALuGkC/x3MQQqAIBBA0avIrBtQI4uuEi3EJh2IEo0QwrsnL d/i/xcyJaYMs3gh0cOZr7NBdQJcsKcn5K0ZtNRG9sqgj3xhDjbRhuWwN+EoJ2cG5awbdmhdTLR z+Z/LWusHHkxn8mMAAAA= X-Change-ID: 20260316-gpio-shared-xlate-708c651cac5f To: Linus Walleij , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Jon Hunter , Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4369; i=bartosz.golaszewski@oss.qualcomm.com; h=from:subject:message-id; bh=ou7reqT/wcXjiO1qmnl2tBuKhN8/ZKlH3/7gf6NTwIk=; b=owEBbQKS/ZANAwAKAQWdLsv/NoTDAcsmYgBpuAsSK9AKCYOcqtpoP4ZrbqOo9FLeV/BjO0QlY fu715pOSbqJAjMEAAEKAB0WIQSR5RMt5bVGHXuiZfwFnS7L/zaEwwUCabgLEgAKCRAFnS7L/zaE w8I9EACLGrAwk33e9D9LoGKvEPaprt6zOon1cBPqlwuHE6TMsGJwI/sJS0v0wcfywT16kUTAg1x 6fd557MHZUwkhsCxdGXAkAKLqplVKUjOPh30+cOT6kGkIoOoX5i849vr4WqFcdGtxQSdDLQXsF8 aaL5HZg4SaA9Zp7XbryAhKK/7G1rTo/0ztloivWXKOON0vKOdT7TsWDrGQqd22gxZT9AQdDtTlf J64lXnVTiy30TIDG4j+wYLgTSwByA/M9oh1AJydJyV+SMPzl1Z4CZ2Hlf5STFrWywiLLzqWiZDP RQAU0lM6LVFNM32vF6cDanTyzdE1BjLPx2y5yab6jrOw8If81X9LCRczYV1nc0TH2wNry0GZPF1 64Qn3BiH9siBJyLaoF0ygfC4WK+kBLIfpUTB1AkTOlnYRKiPuDOTFp1Jn85tdDfpcO3WAFfvjBJ 0F+geIHRDDf3Mo8cvOhuyULO3YmmSYeCLIc1vemCZB21IDyR4yikiBA+tW4EXCADkP6NQaqWSj3 EIxCo6xKG1z5c9bBn/CVdhf/hBi3p2pVlHOE3S1zyhEVyQOE4yCVb/8wQalB7Dm01uFnwgpSNnl A8/+lXdQcydHRXW6y85eAhXsHttFjYORO46K7mC27SIzKJ9OctvMcG/jp9Z6bthl0Hp4yzwWJU+ 3+cCihe9m58EVfA== X-Developer-Key: i=bartosz.golaszewski@oss.qualcomm.com; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 X-Proofpoint-GUID: IpXDL618xoCTZb6BDR33VFrJxEVbF24A X-Authority-Analysis: v=2.4 cv=CKInnBrD c=1 sm=1 tr=0 ts=69b80b19 cx=c_pps a=50t2pK5VMbmlHzFWWp8p/g==:117 a=xqWC_Br6kY4A:10 a=IkcTkHD0fZMA:10 a=Yq5XynenixoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=VwQbUJbxAAAA:8 a=Ikd4Dj_1AAAA:8 a=EUspDBNiAAAA:8 a=hgUgvgRoQYGt6P0yErkA:9 a=QEXdDO2ut3YA:10 a=IoWCM6iH3mJn3m4BftBB:22 X-Proofpoint-ORIG-GUID: IpXDL618xoCTZb6BDR33VFrJxEVbF24A X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzE2MDEwNCBTYWx0ZWRfX5du9mxxncTim Io55hfzOvpAF9b1wC7bvQkYFWL673/pqO1LegszmhUoKWNIvFnro8UW/hohKGlz2GkVWErzZhdT m9Bo1DX+rBd536mDvtlyNqmB171bbLVldr4/y3XYeboii2USd9r8IBMYl0ZstC5drLxIKNBnU3n hzEbpghek9B/pBvAwnsnWIRrWPgRKEfHGUEZmURYWG5iOznXz2WX4sTEL8syCB6gfcXr8bnzwnj F0cVwzZmuGM5C5I2cnA+4xFruKsKjiPM0cTUmkn7x7t+ZfJfoZBsp5RKOmU/oz8ZDUUBI6fnLRp l55RQdk0lFrO0Xr9V6uSJ3lN08ROPTBiyqZkXMVYELsh+3fWawROk819kCJ+DQhYQExBDucZl/r 14S9fG3d5/ukwlw1evgSo9kPRyPFTd9fz6V6MB1xgF/9UnLNZW6d3JA5yAgShlAu2o0XQ4zoP19 r7J084ghuJeelB91/FA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-16_04,2026-03-16_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 phishscore=0 priorityscore=1501 bulkscore=0 adultscore=0 impostorscore=0 suspectscore=0 spamscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2603160104 OF-based GPIO controller drivers may provide a translation function that calculates the real chip offset from whatever devicetree sources provide. We need to take this into account in the shared GPIO management and call of_xlate() if it's provided and adjust the entry->offset we initially set when scanning the tree. To that end: modify the shared GPIO API to take the GPIO chip as argument on setup (to avoid having to rcu_dereference() it from the GPIO device) and protect the access to entry->offset with the existing lock. Fixes: a060b8c511ab ("gpiolib: implement low-level, shared GPIO support") Reported-by: Jon Hunter Closes: https://lore.kernel.org/all/921ba8ce-b18e-4a99-966d-c763d22081e2@nv= idia.com/ Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-shared.c | 27 ++++++++++++++++++++++++++- drivers/gpio/gpiolib-shared.h | 4 ++-- drivers/gpio/gpiolib.c | 2 +- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib-shared.c b/drivers/gpio/gpiolib-shared.c index 17a7128b6bd9bf6023deccee50b2453caebe3d9a..3a8db9bf456daaf021d3c691677= a90fc6da15889 100644 --- a/drivers/gpio/gpiolib-shared.c +++ b/drivers/gpio/gpiolib-shared.c @@ -506,8 +506,9 @@ static void gpio_shared_remove_adev(struct auxiliary_de= vice *adev) auxiliary_device_uninit(adev); } =20 -int gpio_device_setup_shared(struct gpio_device *gdev) +int gpiochip_setup_shared(struct gpio_chip *gc) { + struct gpio_device *gdev =3D gc->gpiodev; struct gpio_shared_entry *entry; struct gpio_shared_ref *ref; struct gpio_desc *desc; @@ -532,12 +533,34 @@ int gpio_device_setup_shared(struct gpio_device *gdev) * exposing shared pins. Find them and create the proxy devices. */ list_for_each_entry(entry, &gpio_shared_list, list) { + guard(mutex)(&entry->lock); + if (!device_match_fwnode(&gdev->dev, entry->fwnode)) continue; =20 if (list_count_nodes(&entry->refs) <=3D 1) continue; =20 +#if IS_ENABLED(CONFIG_OF) + if (is_of_node(entry->fwnode) && gc->of_xlate) { + /* + * This is the earliest that we can tranlate the + * devicetree offset to the chip offset. + */ + struct of_phandle_args gpiospec =3D { }; + + gpiospec.np =3D to_of_node(entry->fwnode); + gpiospec.args_count =3D 2; + gpiospec.args[0] =3D entry->offset; + + ret =3D gc->of_xlate(gc, &gpiospec, NULL); + if (ret < 0) + return ret; + + entry->offset =3D ret; + } +#endif /* CONFIG_OF */ + desc =3D &gdev->descs[entry->offset]; =20 __set_bit(GPIOD_FLAG_SHARED, &desc->flags); @@ -575,6 +598,8 @@ void gpio_device_teardown_shared(struct gpio_device *gd= ev) struct gpio_shared_ref *ref; =20 list_for_each_entry(entry, &gpio_shared_list, list) { + guard(mutex)(&entry->lock); + if (!device_match_fwnode(&gdev->dev, entry->fwnode)) continue; =20 diff --git a/drivers/gpio/gpiolib-shared.h b/drivers/gpio/gpiolib-shared.h index 40568ef7364ccbf08b7f583e279a7d5b572af477..e11e260e1f590c46c5e575d3bb8= f3b5a2240892d 100644 --- a/drivers/gpio/gpiolib-shared.h +++ b/drivers/gpio/gpiolib-shared.h @@ -14,14 +14,14 @@ struct device; =20 #if IS_ENABLED(CONFIG_GPIO_SHARED) =20 -int gpio_device_setup_shared(struct gpio_device *gdev); +int gpiochip_setup_shared(struct gpio_chip *gc); void gpio_device_teardown_shared(struct gpio_device *gdev); int gpio_shared_add_proxy_lookup(struct device *consumer, const char *con_= id, unsigned long lflags); =20 #else =20 -static inline int gpio_device_setup_shared(struct gpio_device *gdev) +static inline int gpiochip_setup_shared(struct gpio_chip *gc) { return 0; } diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6e000ad58a11f7e3de85d8a0630150368acc53ce..1777efe1a986c941da464da9225= 5c261f27a5a6b 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1223,7 +1223,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, = void *data, if (ret) goto err_remove_irqchip_mask; =20 - ret =3D gpio_device_setup_shared(gdev); + ret =3D gpiochip_setup_shared(gc); if (ret) goto err_remove_irqchip; =20 --- base-commit: eadf2995ab7c8158bf694304d41e49cada263277 change-id: 20260316-gpio-shared-xlate-708c651cac5f Best regards, --=20 Bartosz Golaszewski