From nobody Fri Jul 24 05:26:19 2026 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 9EC6733C536 for ; Thu, 23 Jul 2026 03:19:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776792; cv=none; b=te0YnNIpfbSnnkrhU48fwb4/4HlZXvmejckj9LkSCFk91u33kBzaR36acb9RLY+X/GBMQwHb4y6ymOfZYe+a/fJeHlF4re15E8eUSi5/jJV+JI1sURJQJ2jKmXNDctfh66mQxYIdPRhbJPMHVxFyKS8yyEjKIzUW/DbLos7HWFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776792; c=relaxed/simple; bh=mqPLl/v2ZHb0lLzVuot2WAO/fbk6bhNfmEWM56hMkfA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u3ESID26exIWmmX59o7+XeDrHnD+V3/1sIp6UFG7zgpMOXPLVkXQ92Ko/kB+0uTJ18scOfIyN70Giup65R0nNDIfJwb9TTvRX/MLqI6aRiJFqCiKWNxkDxU1dWtAIr/t3vdxXo+1kZ50o3CXJTjlZlBK1KEsKcN/jvkgUa3Irnw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=daXL+BLk; arc=none smtp.client-ip=209.85.215.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="daXL+BLk" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-ca7bea5e5b3so150169a12.1 for ; Wed, 22 Jul 2026 20:19:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1784776789; x=1785381589; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=5//9/KNpBeXSP8zMdzS59AXFLM3ShB/lPJNb0W6WwR8=; b=daXL+BLkrOE1UUgGVn7mHWYmPdd9LS/KKD6pCTktEwOYvLAR52GABoCBa1oAb33Dm7 mTaI2FMZxfJkul3G6Dfwqji+6t63/N75WDytG1dGTBPf0BUIyD2gIUW2eRmg3nC7qY6g jdUWBfg1gucRCZvFiKMyieMWqL6ONIfKnhEeU5gMOnUPrQ8F6xPNgc+HWoj+ICG3zaMQ 7byHJuyevV1fgV2qmDxYfDgUAqsfCDjuJBrr5osCWA1ijwM+EjZxwLDJpTWZDC73duL/ o2wjjl28xf9UTNkwaIlQqYQAH7AQVAKiuUiWJxcBulgMQ24BIId/JF19jDY6V1j2YWtw 4lJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784776789; x=1785381589; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=5//9/KNpBeXSP8zMdzS59AXFLM3ShB/lPJNb0W6WwR8=; b=im5xgXSL7S7rOXEQtqzHN9dMeJOYL62dnaXHtF9Sbi5aQs6j1Idi1Hu40KnNni7k+Q 19JaBqfageIswHx+s1SnxvR7K8St2Ufe4zsbVBajw7UdI7BtPFXUMXxCD1e9vBnd5VT0 NqExSPpN0cuI7xKeXizClO5KId5oWpZ45ul3c6cxpItsHuWipqrt+J3lRrdomBSt785r zimiLMRd4sOtw0tvDyBUFe1VvufeNk0jZIXI+eejyYh7zlpslz6pYvfAzkcNKSj1hfjr 3wwKGjuE6TukklP+JR/jK1i03SMNvyn+zYnjJKNhCQQbmbzA3+t+6E/l0qD/gypU+5So Zsfw== X-Forwarded-Encrypted: i=1; AHgh+RrQdQLj/Fbrm5GT6vbmmeU9LPUmzTa49st9SexZr2zzQ7oLjZgzb19SIFqBtiRjy1RTxn29uF0syuTKHE8=@vger.kernel.org X-Gm-Message-State: AOJu0YwEJCmLz0dH9v/3zC/YHQre0mgQ3inCLbqv6vQLTq5V/LD6Z8aB lM3THSQOanhLIxdffpxqfyg/c5vsNOn2iABjTgMIicEWI7rUFzoo2FPXPFNqK5VRyckOdc7BFF+ Kv8/00NA= X-Gm-Gg: AR+sD10frquTeMWN7hsZNGzinxMZQLcgu2CubrEh+Ty4iTZk1oz6518/JikLrSPpVMK qQ1WvqzrdkaWLpU9SAOfPdZnN0xzhmvm9QZkZ4K+1o5SYDP4kWJkSt3bMpUv85UobnYt40esIFo 8glCf+MZ2tZ95kdSEZMLdLcXh1JBhczccg8VTXlBfrVo/nUMiymgG95Gsmwt+s6xSDq+8RcbQHx azGR+E/0rJmFtgxoMhN/WNQQb4GZP6elzS0l0UaqDSxNvIf0ZfeLp/dXWFQVlNi4DSetphXUZHD 3CcJ99Y70qvNbXiQUg3aN9DvnDwjxjLCmV76qK3yoeVkmLoM7hpsB9z9Q6u0JL7zzFSxVcFz0Cc CxSPnyOLRiwuVNoPmOiL+lUFDZtTh0k/OV+J9PHzG5/y4Miz+awfChmdu1kTQYR3hGnkSTnJNKj ddLA5+ X-Received: by 2002:a05:6a20:a11a:b0:3c0:9c19:65b4 with SMTP id adf61e73a8af0-3c44b2ae267mr1175327637.76.1784776788955; Wed, 22 Jul 2026 20:19:48 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147e1bc886sm13826080eec.26.2026.07.22.20.19.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 20:19:48 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 22 Jul 2026 20:19:42 -0700 Subject: [PATCH v5 1/9] of: hold a reference on of_aliases during alias path resolution 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: <20260722-nh-of-alias-overlay-v5-1-2abe2bb9cdbc@nexthop.ai> References: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> In-Reply-To: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> To: Rob Herring , Saravana Kannan , Frank Rowand Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784776786; l=3488; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=mqPLl/v2ZHb0lLzVuot2WAO/fbk6bhNfmEWM56hMkfA=; b=Xl/x0shU9GkzO2aja8I28OdQaRhTZbm8kGwloGLtBnwAVS4mJ7YxVwm4H3rAZJiH465Ja2fte kzUTcopl18UCP+C7AUtIsY2EU99ueobWyHkfKrHlXL5wQSBFeDJRiRM X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= of_find_node_opts_by_path() walks the property list of of_aliases without taking a reference on the node and passes pp->value straight to of_find_node_by_path(). Take a reference across the walk. The walk itself stays lock-free like every other property iteration: removed properties keep their ->next and are only freed when the node is released, so the node reference is sufficient. devtree_lock covers only the pointer load, pairing it with a later patch in this series that clears of_aliases and drops its reference when the node is detached at runtime. Validate the value before resolving it. of_alias_value_ok() requires a non-empty, NUL-terminated, absolute path: - an empty property has a NULL value and crashes in strchr() - a value without a NUL inside the property is read past its end - a relative value naming another alias (loop =3D "loop") recurses through of_find_node_by_path() until the stack is exhausted All three are reachable with a malformed boot FDT today. The name comparison loses its redundant strlen() pass while here. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Abdurrahman Hussain --- drivers/of/base.c | 20 +++++++++++++++----- drivers/of/of_private.h | 8 ++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 6e7a42dedad3..6f79f593fc77 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -995,6 +995,8 @@ struct device_node *of_find_node_opts_by_path(const cha= r *path, const char **opt =20 /* The path could begin with an alias */ if (*path !=3D '/') { + struct device_node *aliases; + const char *value =3D NULL; int len; const char *p =3D strchrnul(path, '/'); =20 @@ -1002,16 +1004,24 @@ struct device_node *of_find_node_opts_by_path(const= char *path, const char **opt p =3D separator; len =3D p - path; =20 - /* of_aliases must not be NULL */ - if (!of_aliases) + /* the load pairs with writers that retire the node */ + raw_spin_lock_irqsave(&devtree_lock, flags); + aliases =3D of_node_get(of_aliases); + raw_spin_unlock_irqrestore(&devtree_lock, flags); + if (!aliases) return NULL; =20 - for_each_property_of_node(of_aliases, pp) { - if (strlen(pp->name) =3D=3D len && !strncmp(pp->name, path, len)) { - np =3D of_find_node_by_path(pp->value); + for_each_property_of_node(aliases, pp) { + if (!strncmp(pp->name, path, len) && !pp->name[len]) { + if (of_alias_value_ok(pp)) + value =3D pp->value; break; } } + /* the reference on @aliases keeps @value alive */ + if (value) + np =3D of_find_node_by_path(value); + of_node_put(aliases); if (!np) return NULL; path =3D p; diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 0ae16da066e2..9bba999f0bf8 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -215,6 +215,14 @@ static inline bool is_pseudo_property(const char *prop= _name) !of_prop_cmp(prop_name, "linux,phandle"); } =20 +/* alias values must be absolute paths NUL-terminated within length */ +static inline bool of_alias_value_ok(const struct property *pp) +{ + return pp->value && pp->length >=3D 2 && + *(const char *)pp->value =3D=3D '/' && + strnlen(pp->value, pp->length) < pp->length; +} + #if IS_ENABLED(CONFIG_KUNIT) int __of_address_resource_bounds(struct resource *r, u64 start, u64 size); #endif --=20 2.54.0 From nobody Fri Jul 24 05:26:19 2026 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 91E03342146 for ; Thu, 23 Jul 2026 03:19:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776792; cv=none; b=JOr3ZwdpfPWQa0Ql2lRJxpGelYfBF0HJfOTcBgA1PM3dTaW3zPLbWmqV5/nUEIpGbzjWBbfRTNDKbSKFw2WUUCeSEXg5jueXMRtgTJ36eF655dBjef5MkiyenxVFdjZqKwhc4XXVb9yrWm6QGD++oy+A6nH7uMyI1HD6hKrRS7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776792; c=relaxed/simple; bh=cyfrozKWmI8zwHTh+pIB3yrqAf/dTNGWOZ5xvhOFNDU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Xi8+3Tv8b6Fon4C2QLD9CF/+QTEQOoI//Ybu46Hhz3hCQOzkNQvKfcXuD9gAnV45PKCKJSDHjFuHbuXOLIUBR4baAs2UPcKxzPyw47GjIu1cRZqd74nWINbjhcOovygLN1E8eTQ7+idJHFB5AJ5pAAarLeiD1N5GybmgqAvMBK0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=Cv349mtT; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="Cv349mtT" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-38125cebfdaso221501a91.1 for ; Wed, 22 Jul 2026 20:19:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1784776790; x=1785381590; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7BuzcaqsMvQX1aq3iIfilpEcWiOtbsQMEXZm+uuF/2k=; b=Cv349mtTdp8elmByjP4o4JQ4tUsYzOK/L1qONgllpf13T2sfcqH25dX0ELKwVdlQpE xOIDBWbnav7K5vmeIeUzBgO3fPPh9NMaWPvPpLh4U7xzIKYNTpRdAGR3626tQCNFg9xo Wh4dFRjAvu120Iw4WbZzeOJWuzszrxrFqVfh3mI2yo7ej4L/gsF1yrBl2gVMUUHtB/jw ea/KArS8XeE+B54MtEbxRCgsV79otZQZLzHT6ItOnX5kHEnEDex8t1VSRA78DRMdN6Y2 QWhvjXoRgUf9SXfZX8a22VJ85twpeEcNoCZs1Os+OQ+gs4rbD/yGxjtpfMZXmSlIvw3d kBMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784776790; x=1785381590; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7BuzcaqsMvQX1aq3iIfilpEcWiOtbsQMEXZm+uuF/2k=; b=RgQsRbT7tsUiLEqf5Qo3qbjkQ7Iw5V1uIoZlyL6Z/y2ZlX9Wd1DxVhZedCy3uNTI8A MJHUX0xcwiWRmWiCYzpU1YM/xNIm8+BXMsUvkrODRQ33i+9PObjVwr+htVelcHtheO0r /MRyCCAC3leoRRoJWVnxiGvJGWxJl4XLuUSM+5dhiipi64eXD4wNEmgm3vmr2GxzUSvr pCNAkqFJsLo4sqJbQXMx4ZUucUHlsg4sJaJMzeYwSz9rSakheUYqfU/vOvKyB+ZKkaCk wlxHe+z/L1yRg2vm2OzrZzW85KmmHouFCFueaE0I8yGcBO7kzcl3r65P9wlFzGTH9jV0 He0A== X-Forwarded-Encrypted: i=1; AHgh+RpfD48LgHf/nJjJ6uIaigjvEMIYixealrDv623XhNgcWgd/DJdkDtKNmnXxLz1AP5U5ri2C+P5UuBOCKDY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/LdL+1sKhd2MVGjhl1BFvDmsm3kdIZt0tXzZHkd1v00fGlOIg nqnMrcdrWbQsSvR9OJpafvChosFher6s3iHXUlYl5v0Yut7+JAWPNDJPvofMj02YbKE= X-Gm-Gg: AR+sD1116HA+8jDBnDaYyswafvCRvYHjyA9RLMUbH0UW5qbX023nZGm8nzvv7Z0DzWx VPNp5oKW10x/ybWLCOb5dwWgPmIepsROeTAmAUPFmOPvzZgE2LJmGuJHWIxtv82pkB/3evAcC5r JM3mpfpSbfjDVCEoj6516x4/5QpsRVNMssy6ZFuqKzmGNqUMNlyYOOXo1UXqGVsHLK08crUEXxX awc327YdpuGCS+ukPCAYlKZMZZhppOpa369wo+e71v3SKLnsuT5Gtnd5wFfRyGRDcOa+adMNOHV mqF2W8n8rROFfJrNvIdJjuTo8AiZY+t99D1jDCID2mlf5g99U0SRYeCqdrfCiqYkpeaYeZ2XnaQ 4wYqbkTbm/OYFtqJJc2PKmji5XXbUIu5qyPUF7530e7bc7IMJvugKgVpAxYz/ZPkwNLWxOi9o69 J3oNdccYGXJPu9cr8= X-Received: by 2002:a05:6300:6701:b0:3c3:875d:c53f with SMTP id adf61e73a8af0-3c44b244a6emr1447429637.69.1784776789969; Wed, 22 Jul 2026 20:19:49 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147e1bc886sm13826080eec.26.2026.07.22.20.19.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 20:19:49 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 22 Jul 2026 20:19:43 -0700 Subject: [PATCH v5 2/9] of: update /aliases lookup on reconfig notifications 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: <20260722-nh-of-alias-overlay-v5-2-2abe2bb9cdbc@nexthop.ai> References: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> In-Reply-To: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> To: Rob Herring , Saravana Kannan , Frank Rowand Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784776786; l=11660; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=cyfrozKWmI8zwHTh+pIB3yrqAf/dTNGWOZ5xvhOFNDU=; b=VbmZGOPrV4Ep+4uLfWyXN8ooozCOIjC2qWO1hFj0IKgAErgtJ3rFGDhFjkLZB0Z9YtYrr7u/x 3fGHgbaiJFxBMznsPDJA7xjQvRmJpfR6YnTQFC/eqvKc5J6ihieXgZZ X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= Aliases added by overlays never make it into aliases_lookup, which is only filled by of_alias_scan() at boot. of_alias_get_id() returns -ENODEV for them and drivers using alias based numbering (i2c, spi, tty, mmc) fall back to dynamic ids. Register a reconfig notifier and mirror /aliases property changes into aliases_lookup. The notifier chain covers changesets and overlays, so no overlay specific hook is needed. Same approach as Geert's 2015 series [1], which was never reposted; of_alias_create()/of_alias_destroy() keep its names. The /aliases node is matched by name and root parent instead of the of_aliases pointer, which is still NULL when an overlay creates the node on a system without a boot-time /aliases. The name match is exact, of_node_name_eq() would also match "aliases@1". ATTACH stores the node in of_aliases with a reference held, DETACH drops it again and flushes aliases_lookup; the pointer updates happen under devtree_lock to pair with the reader in of_find_node_opts_by_path(). Nodes attached with properties already set are not scanned, as before. Lookup entries are created by of_alias_scan()'s old loop body, moved into of_alias_create(). Entries created at runtime have kstrdup'ed names and an of_node_get'ed target and are flagged "owned" so of_alias_destroy() knows what to kfree(); boot entries live in memblock and are only unlinked. Removal matches entries regardless of ownership so updating a boot-time alias does not leave duplicates behind, which was Grant's main concern on the old series [2]. A new aliases_mutex protects the list. of_mutex does not work here: the notifier runs under it on the overlay path but outside of it on the of_add_property() path. The rework also fixes an out-of-bounds read in the old stem parser, which tested isdigit(*(end - 1)) before checking end > start and so read one byte before the property name when the name was empty or all digits. Such names are skipped now instead of getting an empty stem. Only built for CONFIG_OF_DYNAMIC: there are no notifications without it and the register stub returns -EINVAL. Link: https://lore.kernel.org/lkml/1435675876-2159-1-git-send-email-geert+r= enesas@glider.be/ [1] Link: https://lore.kernel.org/lkml/20150630172131.D4E6CC4041A@trevor.secret= lab.ca/ [2] Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Abdurrahman Hussain --- drivers/of/base.c | 210 +++++++++++++++++++++++++++++++++++++++-----= ---- drivers/of/device.c | 4 +- drivers/of/of_private.h | 14 ++++ 3 files changed, 186 insertions(+), 42 deletions(-) diff --git a/drivers/of/base.c b/drivers/of/base.c index 6f79f593fc77..612e2cd31688 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1925,6 +1925,170 @@ static void of_alias_add(struct alias_prop *ap, str= uct device_node *np, ap->alias, ap->stem, ap->id, np); } =20 +/* + * Protects aliases_lookup and of_aliases. of_alias_scan() runs single- + * threaded at init and skips it; every other reader/writer must hold it. + */ +DEFINE_MUTEX(aliases_mutex); + +/* Callers other than of_alias_scan() must hold @aliases_mutex. */ +static void of_alias_create(const struct property *pp, + void *(*dt_alloc)(u64 size, u64 align), + bool owned) +{ + const char *start =3D pp->name; + const char *end; + struct device_node *np; + struct alias_prop *ap; + const char *dup; + int id, len; + + if (is_pseudo_property(pp->name)) + return; + + if (!of_alias_value_ok(pp)) + return; + + np =3D of_find_node_by_path(pp->value); + if (!np) + return; + + end =3D start + strlen(start); + while (end > start && isdigit(*(end - 1))) + end--; + len =3D end - start; + if (len =3D=3D 0) + goto out_put; + + if (kstrtoint(end, 10, &id) < 0) + goto out_put; + + ap =3D dt_alloc(sizeof(*ap) + len + 1, __alignof__(*ap)); + if (!ap) + goto out_put; + memset(ap, 0, sizeof(*ap) + len + 1); + + if (owned) { + dup =3D kstrdup(pp->name, GFP_KERNEL); + if (!dup) { + kfree(ap); + goto out_put; + } + } else { + dup =3D start; + } + ap->alias =3D dup; + ap->owned =3D owned; + of_alias_add(ap, np, id, start, len); + return; + +out_put: + of_node_put(np); +} + +#ifdef CONFIG_OF_DYNAMIC +/* Unlink @ap; free its storage if it was runtime-allocated. */ +static void __of_alias_del(struct alias_prop *ap) +{ + list_del(&ap->link); + of_node_put(ap->np); + if (ap->owned) { + kfree(ap->alias); + kfree(ap); + } +} + +/* Callers must hold @aliases_mutex. */ +static void of_alias_destroy(const char *name) +{ + struct alias_prop *ap, *tmp; + + list_for_each_entry_safe(ap, tmp, &aliases_lookup, link) { + if (strcmp(ap->alias, name) !=3D 0) + continue; + __of_alias_del(ap); + return; + } +} + +static void *alias_alloc(u64 size, u64 align) +{ + return kzalloc(size, GFP_KERNEL); +} + +/* Callers must hold @aliases_mutex. */ +static void of_aliases_forget_all(void) +{ + struct alias_prop *ap, *tmp; + + list_for_each_entry_safe(ap, tmp, &aliases_lookup, link) + __of_alias_del(ap); +} + +static int of_aliases_reconfig_notifier(struct notifier_block *nb, + unsigned long action, void *arg) +{ + struct of_reconfig_data *rd =3D arg; + struct device_node *put =3D NULL; + unsigned long flags; + + /* of_aliases may still be NULL when an overlay creates the node */ + if (!rd->dn || !of_node_is_aliases(rd->dn)) + return NOTIFY_DONE; + + mutex_lock(&aliases_mutex); + switch (action) { + case OF_RECONFIG_ATTACH_NODE: + /* of_aliases is read under devtree_lock by alias path lookup */ + raw_spin_lock_irqsave(&devtree_lock, flags); + if (!of_aliases) + of_aliases =3D of_node_get(rd->dn); + raw_spin_unlock_irqrestore(&devtree_lock, flags); + break; + case OF_RECONFIG_DETACH_NODE: + raw_spin_lock_irqsave(&devtree_lock, flags); + if (of_aliases =3D=3D rd->dn) { + of_aliases =3D NULL; + put =3D rd->dn; + } + raw_spin_unlock_irqrestore(&devtree_lock, flags); + if (put) { + of_aliases_forget_all(); + /* may free the node, so must sit outside devtree_lock */ + of_node_put(put); + } + break; + case OF_RECONFIG_ADD_PROPERTY: + of_alias_create(rd->prop, alias_alloc, true); + break; + case OF_RECONFIG_REMOVE_PROPERTY: + of_alias_destroy(rd->prop->name); + break; + case OF_RECONFIG_UPDATE_PROPERTY: + if (rd->old_prop) + of_alias_destroy(rd->old_prop->name); + of_alias_create(rd->prop, alias_alloc, true); + break; + default: + break; + } + mutex_unlock(&aliases_mutex); + return NOTIFY_OK; +} + +static struct notifier_block of_aliases_nb =3D { + .notifier_call =3D of_aliases_reconfig_notifier, +}; + +static int __init of_aliases_reconfig_init(void) +{ + return of_reconfig_notifier_register(&of_aliases_nb); +} + +/* of_alias_scan() runs pre-initcall, so the boot-time scan is complete */ +core_initcall_sync(of_aliases_reconfig_init); +#endif /* CONFIG_OF_DYNAMIC */ + /** * of_alias_scan - Scan all properties of the 'aliases' node * @dt_alloc: An allocator that provides a virtual address to memory @@ -1960,42 +2124,8 @@ void of_alias_scan(void * (*dt_alloc)(u64 size, u64 = align)) if (!of_aliases) return; =20 - for_each_property_of_node(of_aliases, pp) { - const char *start =3D pp->name; - const char *end =3D start + strlen(start); - struct device_node *np; - struct alias_prop *ap; - int id, len; - - /* Skip those we do not want to proceed */ - if (is_pseudo_property(pp->name)) - continue; - - np =3D of_find_node_by_path(pp->value); - if (!np) - continue; - - /* walk the alias backwards to extract the id and work out - * the 'stem' string */ - while (isdigit(*(end-1)) && end > start) - end--; - len =3D end - start; - - if (kstrtoint(end, 10, &id) < 0) { - of_node_put(np); - continue; - } - - /* Allocate an alias_prop with enough space for the stem */ - ap =3D dt_alloc(sizeof(*ap) + len + 1, __alignof__(*ap)); - if (!ap) { - of_node_put(np); - continue; - } - memset(ap, 0, sizeof(*ap) + len + 1); - ap->alias =3D start; - of_alias_add(ap, np, id, start, len); - } + for_each_property_of_node(of_aliases, pp) + of_alias_create(pp, dt_alloc, false); } =20 /** @@ -2013,7 +2143,7 @@ int of_alias_get_id(const struct device_node *np, con= st char *stem) struct alias_prop *app; int id =3D -ENODEV; =20 - mutex_lock(&of_mutex); + mutex_lock(&aliases_mutex); list_for_each_entry(app, &aliases_lookup, link) { if (strcmp(app->stem, stem) !=3D 0) continue; @@ -2023,7 +2153,7 @@ int of_alias_get_id(const struct device_node *np, con= st char *stem) break; } } - mutex_unlock(&of_mutex); + mutex_unlock(&aliases_mutex); =20 return id; } @@ -2041,7 +2171,7 @@ int of_alias_get_highest_id(const char *stem) struct alias_prop *app; int id =3D -ENODEV; =20 - mutex_lock(&of_mutex); + mutex_lock(&aliases_mutex); list_for_each_entry(app, &aliases_lookup, link) { if (strcmp(app->stem, stem) !=3D 0) continue; @@ -2049,7 +2179,7 @@ int of_alias_get_highest_id(const char *stem) if (app->id > id) id =3D app->id; } - mutex_unlock(&of_mutex); + mutex_unlock(&aliases_mutex); =20 return id; } diff --git a/drivers/of/device.c b/drivers/of/device.c index b3dc78f2fa3a..fa0cc8129ab0 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -237,7 +237,7 @@ void of_device_uevent(const struct device *dev, struct = kobj_uevent_env *env) add_uevent_var(env, "OF_COMPATIBLE_N=3D%d", seen); =20 seen =3D 0; - mutex_lock(&of_mutex); + mutex_lock(&aliases_mutex); list_for_each_entry(app, &aliases_lookup, link) { if (dev->of_node =3D=3D app->np) { add_uevent_var(env, "OF_ALIAS_%d=3D%s", seen, @@ -245,7 +245,7 @@ void of_device_uevent(const struct device *dev, struct = kobj_uevent_env *env) seen++; } } - mutex_unlock(&of_mutex); + mutex_unlock(&aliases_mutex); } EXPORT_SYMBOL_GPL(of_device_uevent); =20 diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h index 9bba999f0bf8..731b606ae3e3 100644 --- a/drivers/of/of_private.h +++ b/drivers/of/of_private.h @@ -17,6 +17,11 @@ * @alias: Alias property name * @np: Pointer to device_node that the alias stands for * @id: Index value from end of alias name + * @owned: True for runtime entries, where the struct and @alias are + * kmalloc'd/kstrdup'd and freed on removal. False for boot-time + * entries, which live in memblock (@alias points into the FDT) + * and are only unlinked. Every entry holds a reference on @np; + * removal drops it regardless of @owned. * @stem: Alias string without the index * * The structure represents one alias property of 'aliases' node as @@ -27,6 +32,7 @@ struct alias_prop { const char *alias; struct device_node *np; int id; + bool owned; char stem[]; }; =20 @@ -40,6 +46,7 @@ struct alias_prop { =20 extern struct mutex of_mutex; extern raw_spinlock_t devtree_lock; +extern struct mutex aliases_mutex; extern struct list_head aliases_lookup; extern struct kset *of_kset; =20 @@ -223,6 +230,13 @@ static inline bool of_alias_value_ok(const struct prop= erty *pp) strnlen(pp->value, pp->length) < pp->length; } =20 +/* the /aliases node: root child with the exact name "aliases" */ +static inline bool of_node_is_aliases(const struct device_node *np) +{ + return of_node_is_root(np->parent) && + !strcmp(kbasename(np->full_name), "aliases"); +} + #if IS_ENABLED(CONFIG_KUNIT) int __of_address_resource_bounds(struct resource *r, u64 start, u64 size); #endif --=20 2.54.0 From nobody Fri Jul 24 05:26:19 2026 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (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 E84FD3515FF for ; Thu, 23 Jul 2026 03:19:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776793; cv=none; b=JGxss3zU4N6hzBDLbHKExOsfSQHxq8BwLyJAbsDtA7QjuarFDjzfUgIGX9Bkteucq+HO3+vMls3e7tOWsgIrVdBZkjwcD/a0WBqB+jLPlh+8C9JUzXow/ArvAnzZzj1V7M+aWwxc+Oo5USkghJvL+DHjiS7oH8ZAH1Mp+Ti28XU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776793; c=relaxed/simple; bh=i+iwVi9KMRy/SRzPz0dFMHY5QfWjU3ehExfRWdvyWCg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PRLfA8E9mbPsw6aeWVwGrd5I4H+w2LTnr8exnnodAU9OCVPyCicZz7kkU8SPa77BxMgPIH2ALgmMfoHjQ1k7QJ/UjTrZegOt22YiKP5OiFgNJ+MF/yx0mVLJoJx8hG8sXIT/CSKhOE5x32ZAYhUK+ole2n73rYU0kAju04benR4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=i1wiQKdT; arc=none smtp.client-ip=209.85.215.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="i1wiQKdT" Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-c9e30214d8fso141188a12.3 for ; Wed, 22 Jul 2026 20:19:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1784776791; x=1785381591; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=CUT2qIYHjpXWpwH1J8XuYKZa+9kxUUZTpxZC6ZkH8Ds=; b=i1wiQKdTz6eRXOBiSGmhBpFiuhq06BeUnIp+LB2sbdEI/PXbQtxLHPTQhNj9DdGo76 tkxNwvEkGqYckm+WeEpIoHCrpXJ6OGbZY4cm7rxXj/eIp76YqSn3ygsCTrbmgRz2RLgH 5jhm+pV15y59m7wtOSzJC+kDjNntYD4JiP/YdRLRv5J43RMI0emqpLthcrRNS+ZbXYW7 ORMCx0WCW+sgLST88gRoXCI0DvCuCkr95B54AB/GU8XqtBMyOT8L4vsP8pAKTiRS0WA+ 3xRNt7dZ/FhENqrfkdo+ObFZOVczccJki2x/ZKuvLpBN/Q32LSaWtkQn/UESpOQoKa0l oO8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784776791; x=1785381591; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=CUT2qIYHjpXWpwH1J8XuYKZa+9kxUUZTpxZC6ZkH8Ds=; b=H3GtKIQcqNIues8Dkjo3OutU07vlLvS3CQeL0XdPtn9H/3/2OQEyCvE9vPUc2I3qsf FKh3aly1N9op88M0qXMajvaBvriXfQOkdLDLe/7BovBJV06bZy59XX9mnPvdZLt/X4Z5 F0qtScgMOhpiqoDjRFZjLY7yqXTiIftooRlHEjrGM9eE1tokSnHKpwMSgzUKrsc/q7hY k1wma1X4nHRAnZgOKo1P7xQku8UN5kde+dKnBvVh+rxf6pcKepQDzwI+xPuIDhanJd0E GSdIlPObOlIg0mwaW4YfH3jt7rNMIopyXK7M8NdVuUrsW4UAOMbcRPs8nVhrMMznsBS/ V9hA== X-Forwarded-Encrypted: i=1; AHgh+Rr/6+mrCx3JYeDzaYcsNGaQmQh27Q5YxFuHZ3VB0cb5wv1feFVOdC79nTQe87h3Uc5OiT3HR9YWaFNAUyk=@vger.kernel.org X-Gm-Message-State: AOJu0Yzq/x1ypMlnIRHrRwhtQhH4Nm1CFMaSfAFUXwNY1Xpnwmbtgqym ARA9juF/lvRBeMoJ38IGkOAfUsaZ8Lu9LgsunrZ4WCn5nvJ/5GcsiqQ3BID/Ev3XfP0h5sz5HH8 BFmAd4Nw= X-Gm-Gg: AR+sD10uU8YcTLJO2q/5mECqItHhlhGjpc4nwS4e8J0lXBxB0ki96Gw65rgOgyE67nx sfLOKbLRtx6UKdFVJdUBTBaAsksreXc2V4ND4K/Z5749uNRFmZLHOPzTUkA0DS+33O/I/JvJ9sY r6wOtuWXsiObTVt3uIl5XD+3SzT7xUF+DxSUmyykb4FO0VYWYFXpk344pSAxevHGM3sxjDuzy8K oxV1WAcvsTZnD6q4J2NMoqgAYn7OhBoE8Hl1uNCuw74af479pAUBXDhiP9gq/IT2xOVTbGP6WxO QYandsaO1mJiz/u+ws9aLspt1Ly6GAttP6sF8eszYYYQ0UAVf8S0BKV0O6otVZw7+R7hPUhiZuY Ob4+yhLYgiKeGyWRh1uL+YCxnE2n+qYeiRmcRICQ/+pRw3wTZeSwcVVMGTBgsmbS98FUiDtOEKb qYejSD X-Received: by 2002:a05:6a20:6a1c:b0:3c3:aabb:dba3 with SMTP id adf61e73a8af0-3c44b2c1e80mr1212936637.76.1784776791005; Wed, 22 Jul 2026 20:19:51 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147e1bc886sm13826080eec.26.2026.07.22.20.19.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 20:19:50 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 22 Jul 2026 20:19:44 -0700 Subject: [PATCH v5 3/9] of/overlay: look up absolute target-paths absolutely 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: <20260722-nh-of-alias-overlay-v5-3-2abe2bb9cdbc@nexthop.ai> References: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> In-Reply-To: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> To: Rob Herring , Saravana Kannan , Frank Rowand Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784776786; l=3883; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=i+iwVi9KMRy/SRzPz0dFMHY5QfWjU3ehExfRWdvyWCg=; b=l0wvTeuAKY9+ho8vKXqb9+Xkgl9tdYYYlW6Cnd27Unt+4yQcFrFxGQxeUHWIK0nsMfVdMGIvz 0h1grSUgjUGBeRxsk+zVG3uW7cAt/pW6J5cbB2/kHLlzVbKz+YZUEfe X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= find_target() with a non-NULL target base concatenates the base path and the fragment's target-path via "%pOF%s": target-path=3D"/foo" resolves to "/foo" and can never reach the DT root. An overlay applied with a base cannot both extend the base subtree and add /aliases entries, which is what a PCI device declaring its peripherals under dev_of_node() needs for alias-based bus numbering. Treat any non-empty target-path as absolute. An empty target-path still means the base itself, the only form used by the one in-tree caller passing a base (drivers/misc/lan966x_pci.c). Spell the contract out in the kernel-doc for @base/@target_base and in find_target()'s strategy comment. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Abdurrahman Hussain --- drivers/of/overlay.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 08d5351746be..74aea704835a 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -688,12 +688,15 @@ static int build_changeset(struct overlay_changeset *= ovcs) * * 1) "target" property containing the phandle of the target * 2) "target-path" property containing the path of the target + * + * With a non-NULL @target_base, an empty "target-path" means + * @target_base itself; any non-empty "target-path" is resolved + * absolutely from the live-tree root. */ static struct device_node *find_target(const struct device_node *info_node, const struct device_node *target_base) { struct device_node *node; - char *target_path; const char *path; u32 val; int ret; @@ -709,23 +712,14 @@ static struct device_node *find_target(const struct d= evice_node *info_node, =20 ret =3D of_property_read_string(info_node, "target-path", &path); if (!ret) { - if (target_base) { - target_path =3D kasprintf(GFP_KERNEL, "%pOF%s", target_base, path); - if (!target_path) - return NULL; - node =3D of_find_node_by_path(target_path); - if (!node) { - pr_err("find target, node: %pOF, path '%s' not found\n", - info_node, target_path); - } - kfree(target_path); - } else { - node =3D of_find_node_by_path(path); - if (!node) { - pr_err("find target, node: %pOF, path '%s' not found\n", - info_node, path); - } - } + /* an empty target-path means the target base itself */ + if (target_base && path[0] =3D=3D '\0') + return of_node_get((struct device_node *)target_base); + + node =3D of_find_node_by_path(path); + if (!node) + pr_err("find target, node: %pOF, path '%s' not found\n", + info_node, path); return node; } =20 @@ -737,7 +731,9 @@ static struct device_node *find_target(const struct dev= ice_node *info_node, /** * init_overlay_changeset() - initialize overlay changeset from overlay tr= ee * @ovcs: Overlay changeset to build - * @target_base: Point to the target node to apply overlay + * @target_base: Target for fragments with an empty "target-path"; + * fragments with a non-empty "target-path" resolve + * absolutely and ignore @target_base * * Initialize @ovcs. Populate @ovcs->fragments with node information from * the top level of @overlay_root. The relevant top level nodes are the @@ -982,7 +978,9 @@ static int of_overlay_apply(struct overlay_changeset *o= vcs, * @overlay_fdt: pointer to overlay FDT * @overlay_fdt_size: number of bytes in @overlay_fdt * @ret_ovcs_id: pointer for returning created changeset id - * @base: pointer for the target node to apply overlay + * @base: target for fragments with an empty "target-path"; + * fragments with a non-empty "target-path" resolve + * absolutely and ignore @base * * Creates and applies an overlay changeset. * --=20 2.54.0 From nobody Fri Jul 24 05:26:19 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 C814E348465 for ; Thu, 23 Jul 2026 03:19:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776794; cv=none; b=asQdD0222iN96YLHWcnqMOnrVnG1ecJkYbmQWJVPmmj83tn6HWYI0bxYwsP3NK4CtbWFIecroIj6gJovJCqPRVqRLJf0u7cy/H/yShKRT6EoZYKa+IO4vPF3lL6sYdMqSB5OcyzjUQ4E8jAiD+IPFVw2lNOk+UK4SeDW/2Xtwk4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776794; c=relaxed/simple; bh=y82td47R6V/tWGYU6bxKbZBUuC/UthUD3LtG/Zph//U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JdzfI95IL7tvpa8kTxBQ3oMl5i9UCrh4+sbN5fR1sHOKnfJzZiI3fUf5FTU2vPaN1bUJR+2ycjAlfnN17HApTBDxUyimEV5XZawNMHuOJjh5SMsna7QGKeoXzWJ2LJnvbaOWphNy/WlK1AOhFd/uIwi4NKRT3yG3p1Q5QXc2zEI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=VW9EoQ/2; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="VW9EoQ/2" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-848743155bcso52300b3a.0 for ; Wed, 22 Jul 2026 20:19:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1784776792; x=1785381592; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=GC82QffMucP6sKMAwijB741bfjScziJk9di2u49dRhg=; b=VW9EoQ/21ADgGDpoBlPg8IXpNiZt+MsfrBoPZQpPFycW7UKkd4PyczKbJ3/6bQHjzh W60bq3I9/UScnSAng65Znhyv4gxrUuW59+8KjSaJi/GlZX9Ex+OTDH57B5GquK3NeU23 06BumfE/QrGSK6ZRMaCWFchWIHXuri9U0b/qItGyHkoNd9cE1NdPZMpVjIEUJLyqM7Zq EFiNv3tclIpFrrcXo9ScQTP9iLh24upN4x+AZWkVW6IVK4PEYkzuSlsNqERMowkVDI4i 4SuWz0SR90LdaVETwxaxSnV8wuj5AQ8JqqZKWqFJticwwNR6ASaPenzf7R94zvgIgjj2 gCuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784776792; x=1785381592; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GC82QffMucP6sKMAwijB741bfjScziJk9di2u49dRhg=; b=rEhxvdFCy5Wv32YMt8YNLL1fSGO5G6c8nfdOD+Jf2Js0t5lODzx1qwAfVGNETeIw95 JOt4huXNgivJi7QcfnPCkOybuTWzv+caDnCnmlR9L8DkCC06snde0wgBhYdK+A1yafCo HNVfr2/i56VpKxOjSNYUYGU0HgFvQIquNSwTZNkm52IoBnC6Ocj2P0Aazslb3o0dZWoN rfIpZtQjVis+684XLGwwF9P9tmO8tf0yiJv1QWhtSmA420U7CyVXnE1ri0xxkqZn6Bpd IHglUi/VIKyxhD+VLtcjgD9PFdF+c2WGuQIge7+AeAXT3DeVhxrU7nRxX1Uzxp8AQkuC Ncfw== X-Forwarded-Encrypted: i=1; AHgh+RrWEHK7G3y1KZkeUzIVdO2xMGasGKyLCqp2WLmsc4JStok+MP0W0iAHfZoeUDFlk08H9ot/h7Jizzi8td4=@vger.kernel.org X-Gm-Message-State: AOJu0YyKioUwSGOkdkZRQvLHjr3yaHDL4KyooqfCEmRMEBhCGc+s+lZJ UkHiNOCLNo0FYB23/49oU3O4SB687Y9usz9tucDyqL0t/EnTEDo4EpHgePYYVNgclclw8oaF/F7 FF4WW4vE= X-Gm-Gg: AR+sD10aiykCYHPUwjY5G1nK23lkXlI7NkWvWN5F03DqnJNjLKEs9dqMgMxzPfWf2y9 w6wBICOy+XozFIIQL7UYS6vnrVto+JTVn8/Ytd7aOeFZKZQ+NJX0vnHRTK5TLYd+AU7rwafvGKT eQVUeLx6/2KHF+1C/i4f3NtkCm5C/WgxGYrn2kWmYY6LCHf0GGrRR8DhSmobUWSHhJG3kt5LpIT YiANFRNSvau9hG8dGVM6aieMchbiJ8NLJhw+SuNkLgqip7ONw89wmxvWMkXEn7aFJJdbZB3Gw3B jn3+5WiU0roGKVeeTMIzfgpkw4JZWW5d3oQIFol/C3AUkuEJUxFNc30WiXqiIRSZAKD5NS/i2mK eetsAXARbQdJZ2VXN/2Ar9XW27chIedeVBIxzJ7cU9GI5UWD38yYVFckI5EXbFeZ+psoDLCGkpJ yEX5+I X-Received: by 2002:a05:6a20:9398:b0:3c3:66c5:68d6 with SMTP id adf61e73a8af0-3c44afce727mr1346558637.9.1784776792037; Wed, 22 Jul 2026 20:19:52 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147e1bc886sm13826080eec.26.2026.07.22.20.19.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 20:19:51 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 22 Jul 2026 20:19:45 -0700 Subject: [PATCH v5 4/9] of/overlay: put property on deadprops only after changeset add succeeds 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: <20260722-nh-of-alias-overlay-v5-4-2abe2bb9cdbc@nexthop.ai> References: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> In-Reply-To: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> To: Rob Herring , Saravana Kannan , Frank Rowand Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784776786; l=1617; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=y82td47R6V/tWGYU6bxKbZBUuC/UthUD3LtG/Zph//U=; b=Orwg/c5ZlWJdMJQf0tep4akQt9jToVvlCTDcva+pScmy/pwPmQKCsHc8NzgP1UE9JcTODBLAS SCoe/ZTQ+G2Bqq4eZq5TZaLrr2GfjSERRy3IQVOBgoJ7FXxi8elnObB X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= add_changeset_property() links a new property of a not-yet-live target node into the node's deadprops list before handing it to of_changeset_add_property(). If that fails, the error path frees the property but leaves the freed pointer linked in deadprops, and of_node_release() frees it a second time when the aborted overlay's node is released. Record the changeset entry first and link the property into deadprops only on success. of_changeset_add_property() never looks at the node's property lists, so the order of the two steps is otherwise immaterial, and the error path frees a property that nothing references. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Abdurrahman Hussain --- drivers/of/overlay.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 74aea704835a..284c9bc6c9cf 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -358,12 +358,13 @@ static int add_changeset_property(struct overlay_chan= geset *ovcs, return -ENOMEM; =20 if (!prop) { - if (!target->in_livetree) { + ret =3D of_changeset_add_property(&ovcs->cset, target->np, + new_prop); + /* the detached node owns the property until the apply */ + if (!ret && !target->in_livetree) { new_prop->next =3D target->np->deadprops; target->np->deadprops =3D new_prop; } - ret =3D of_changeset_add_property(&ovcs->cset, target->np, - new_prop); } else { ret =3D of_changeset_update_property(&ovcs->cset, target->np, new_prop); --=20 2.54.0 From nobody Fri Jul 24 05:26:19 2026 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.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 9582A3612E8 for ; Thu, 23 Jul 2026 03:19:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776795; cv=none; b=AKE+eubKn0YU2nIFjPVyqk25AtchRFtinJus/bVgFE3C0tRdK04KUaFyjI8ljQlyGGnk3Mxp6dN0L5X/pMC44Ye2XROV4Avh7PRj5delxlFpz3P7Ds9+l8bau7VwpcCTKUtZ1/ADrtMnXKVVhUr2q1R8tfoXaHcAo64YPptvxts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776795; c=relaxed/simple; bh=FJXCevPYrSwYv+Fgo0XX5Tikn5UQNsOn5GQBSuFOS0c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZiRRzwEL+CcKGA1ERcJL7MVm6us2cxAAvz/52aj7uz7q9K4tLddOghHfaeXI/dyFc0pjlHhK71PU5nuv3+TZQTKqksGqPV1EOKy419eJITrYQ8og9An1YRkx6Trw5xAlu7SgtFYqMRWK1TPUlyRtXNFwsxQ/l6mlGXZS+txcg1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=FsbR1geG; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="FsbR1geG" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2cad4170e8eso2787645ad.3 for ; Wed, 22 Jul 2026 20:19:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1784776793; x=1785381593; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dEMNIYa17ALMCA3G5BQkwztf7SHhY+1D/nHSwLmqxWI=; b=FsbR1geGa6xH7VzJe67zbVXKuacuDTTuvyl/wENvGpylohJ/ZFJ/4eTNtDtajdI8Bf QMZKB7k7xnOuPREKyOYo4ns1P2Rbzyq7xMietH/omI2RTKsPCSIkj8jHhB8zvA8LHdH8 pZSrFMJKdWASAdIvqyR4+e4MgZWpL27OHDNDj+AsS2bBLW7b/t+3N5KpJPsXIhsO59WN MeabvZYv6Oks0MYXir5WHOyhIVslu9wp/FhoJ+PQfhyqfhNp2G2Xk10ojCjOaeCPlADP OMqrehc4Cht4nBOUxi3ZcvVapMktkdChF9f/jmhMISnVVWOEm/UN6Dj4NYe/+dH8TdqS Ydjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784776793; x=1785381593; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=dEMNIYa17ALMCA3G5BQkwztf7SHhY+1D/nHSwLmqxWI=; b=DcrRr/3EJubRVGBBb2JmhBinPRSXY5zIUV02CowVmqUtw8Q/vH1GjDsavmw8wFivo8 3EpNz4bm9kbFpa+9EezM/JiuhIQ+dT2Q0QG5smMXjoRIg1GJ9I/cfL2W4qTnOZ5+nSJk iaaJCWKv3XGmyic9XC1+gJNZPeXx8f0vQ8WAAyIVWbraJVR0JNB6nvKLKT10M2dnzAg5 HFmB9gcH23muGh0iEF4vQWwyuJGCvKs/9mOYZrhWUviej90ilQ+65FlYaqi6FoVuE2uW WtsWj2enywZY9b6QlkB2y3lbZArCptAmfegW5G8Yb07UdqtK/gXBwqZSeQ9TXpLXgc8E ObUA== X-Forwarded-Encrypted: i=1; AHgh+Rp6wLEqg2V3VPooQInbtT3NFQDREgoo2z0fYN6xRIVsiMRTAd4aO6vXS5gfv8YW4Ib3AbcnjFpgkO/XfHc=@vger.kernel.org X-Gm-Message-State: AOJu0Yzowi/MY8O3P0GYyyNa04sGQ/EkLWIvklG6dJAQdqJB4dxEV6Ft 4QOC382HDgSWX6ZRTdg0UwsD3gtKHjBYt7cNYoYR7MAz34Rx6jBwMMPUcZhcNxWYleo= X-Gm-Gg: AR+sD127uvNhLPGbVdgFABAYmUDr6+HwL7I8K/zQPYQb0OCqKtVplnxFnwIgdBasGEZ vqBzMRUGJlOhWXe0CGZXKg2xGcgCpgmwSxLJXzyJOI010s8uQLkop90MjdsAHKMXHsQg02/wRYd A9rhMG+K/Yo0mkxi4VPmq8AwvKSWziBQ7whOWKnLHR7t8/5uRKj/MeRx9Y52cMa8glTuM3mBXeU dcuRHzPbzDtyV2gqFC8zitmKTIl9MNHNuGZs0/vSJHo22pj2H6pttMb3wFNHsdCCGlmweqVl8ry rBLblvwFY/Kgo/QYPXOVPptdqWUNkIaNHB0ySAMjpZAD/fPfa00Bk14PaojmnjkyvqFaDNMfL3B HLCWoe3zfB6peuLD6jBWhwyQrAMJu2dcB3pI7kYHyE3Q3Szezk5bNZIt8xevftzpcBQ+K2SWcW0 CBVh20 X-Received: by 2002:a17:903:22c7:b0:2c9:bd37:ae76 with SMTP id d9443c01a7336-2cfa6f7fc67mr16618365ad.47.1784776792932; Wed, 22 Jul 2026 20:19:52 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147e1bc886sm13826080eec.26.2026.07.22.20.19.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 20:19:52 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 22 Jul 2026 20:19:46 -0700 Subject: [PATCH v5 5/9] of/overlay: don't keep a negative id in ovcs->id on idr_alloc() failure 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: <20260722-nh-of-alias-overlay-v5-5-2abe2bb9cdbc@nexthop.ai> References: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> In-Reply-To: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> To: Rob Herring , Saravana Kannan , Frank Rowand Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784776787; l=1193; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=FJXCevPYrSwYv+Fgo0XX5Tikn5UQNsOn5GQBSuFOS0c=; b=d+UHW6wZ5Nee8/xiGWLc3CBVKpCDCBMvNLEo3ZQLq4jPTOk99Yj7sT/TaxmGnrHnYqUpManki 7zXqgmKVEMBAozBPOrM9fE5HzBd3+Bief2/xJ2gnGt07cVVdn4iDJpp X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= of_overlay_fdt_apply() stores the idr_alloc() return value in ovcs->id before checking it. On failure the stored id is negative and the error path runs free_overlay_changeset(), whose "if (ovcs->id)" check passes: idr_remove() is called with a negative id and list_del() runs on ovcs->ovcs_list, which is not initialized until after the id allocation. An allocation failure at that point dereferences NULL. Reset ovcs->id to 0 before taking the error path. Fixes: 61b4de4e0b38 ("of: overlay: minor restructuring") Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Abdurrahman Hussain --- drivers/of/overlay.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 284c9bc6c9cf..f1aa8574069a 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -1038,6 +1038,8 @@ int of_overlay_fdt_apply(const void *overlay_fdt, u32= overlay_fdt_size, ovcs->id =3D idr_alloc(&ovcs_idr, ovcs, 1, 0, GFP_KERNEL); if (ovcs->id <=3D 0) { ret =3D ovcs->id; + /* free_overlay_changeset() treats a set id as registered */ + ovcs->id =3D 0; goto err_free_ovcs; } =20 --=20 2.54.0 From nobody Fri Jul 24 05:26:19 2026 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 467CD3624B8 for ; Thu, 23 Jul 2026 03:19:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776797; cv=none; b=tYEEMSwUek0uXC+YsogQgH/LhjvA7jOPFOOrF+xy1IbHhjOf6txD4JdM1XpkDE7y4jXPlUKgrLuKjgS391fF4D6kwfyB8MEbpXstRGtXFc+u3gaJCC2YRBF0kIfq9mCoGY/SXy8yGC5ezSivHCg6IqR1U2EoBIAuuAO6lJSyPyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776797; c=relaxed/simple; bh=7hLPGvySNdkYHchBXO/iRfhwHDLyA7Ot2MizQ13r8lI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KlE/NKItvNnrIKokokavAS7yREtRykzm9zEghinG7/rOKdmPnCGlOUGVr5SyvvQ4c7NGOvv0dPOV6CUYq0cDbVSSEoHaE2gkPn2uaUn93IN/wjL3IuTO/5c3/WfTTTkRn0zbPLCUk1ScXCWnRMupk+cD6KXQfz84dO1k2KJPYG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=Penh1sZ8; arc=none smtp.client-ip=209.85.215.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="Penh1sZ8" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-c9e7391839cso192541a12.0 for ; Wed, 22 Jul 2026 20:19:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1784776794; x=1785381594; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=rfoN89nIUf/cQZW3GdB/s+JZP3BlCX2T5A2tIBLDC3M=; b=Penh1sZ8g9EstD6uMvXuMrTFpdqhixpDTTscxCqnno+nqFFNjrdgiHO2x3uCeX6DH5 ETgRp+vyuBqw8gbT3CCtbSIqVct51bIPbt/uSfIO3l90YFtf1U4Z2+hGN61OIAxubyhQ /ZbSlZFa65CYlEjr34EgUWCSuXtq2L3dUEC0WYuMQiqyonWbYrPpErAAPdYLO/MjOsT7 wRc5dM+8P5DAOUWwMWxBu5cyxOcou+bigbPfccpxltPHeODJcoQvN1Y8Gi8GJk+zyoJU H1krsMRfqgblNXhCby/0l+nNJ/PHdhA44LH6+OXpeMfjDWSzSxDYzE6eci3lfMA/cI7d o1Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784776794; x=1785381594; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=rfoN89nIUf/cQZW3GdB/s+JZP3BlCX2T5A2tIBLDC3M=; b=LgCkUodKoINJOjF4ugANPUidyxAFfbyaUa8U1QtzG8cQ5bowqFBEurMNLI/MRgw3rf IZF336vhr72DbkaEK7SRCpr0r2rKME0LDBokvqL70/HtRUiWcAf4eltqb0mSMM1v3OXG 8GoYJWiz62lPuymrjEPkgrLMbNIp/aXJ7ubQh+9kq7UrsPwBKZefm9VL5dDvjuufG6rk EN8jzyqTJqn22yV4rsJUmSyriOEocqAqRwjUnn5XFIPr0/nPIGmPsm+b8GAMBdXRtlAF IwucjEcTKcj8nAWLCzQrVEMILzTghfpsF+RFzIkmmoozgeTqzqUnnJMx1hUrFCYVkv0k h/lA== X-Forwarded-Encrypted: i=1; AHgh+RrZ8O+5v0wQHXTnNEK82p9y4yL1tR7ZvkRF0v3Nr1wLzI305MaKRVLgmzmLDb+j/cYO25iJ2qcVVEPXaFY=@vger.kernel.org X-Gm-Message-State: AOJu0YzVP07cAl92U2Bdzmv2sq/gSptD6fIAWmCuWC+0NAkKDqdp25eD dnRycB1pZSu4I5R7szUTySYb3Z2k5jFgd7nFer0ioJLSDYoKgUu7Sm07W7kx82bX9/U= X-Gm-Gg: AR+sD11o9PJTW3AMoxaINgNAZeG5N8jrnnThRsQEJXqcwfbYPueNRsNlZKrhnkgTdgC ELwgdQmrRZv9eRQIJrdqaKnjw4KbeL5iuekyS71+hr/YQEf+3gL5qUvWfdEvYq7cN5QTbFhtYvx ctd7MTOkP01BcsfFMEz0xtpq93xYxfZkAVT3YrtosxVzwK2DH18xHDlPRLvRuuOg2Hi2o8ofIav jswWWlYmmVTIF5Fouwj8RNRBr2LRsrtexipSo/Q0YSJKuRULXL9gnQP/89ajnEnGQxpjzISow80 O03pauNGpyL8/YtIYTnZXWIdjc8c+smOMTpdbm1eikzj/VPr8TrVDBHWWfmPxGC+kEnwxmGP9lo r1ygo4pT83N7judUsb2tTxBSyBKMVLcuTO2ES0lUgY34LPWfGKJV37Ht82oaNl5uA072ax/XjzK OXk7HS X-Received: by 2002:a05:6300:95:b0:3c4:1708:9cd8 with SMTP id adf61e73a8af0-3c44b2848cdmr1324182637.76.1784776793750; Wed, 22 Jul 2026 20:19:53 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147e1bc886sm13826080eec.26.2026.07.22.20.19.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 20:19:53 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 22 Jul 2026 20:19:47 -0700 Subject: [PATCH v5 6/9] of/overlay: don't create "//" paths for fragments targeting the root 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: <20260722-nh-of-alias-overlay-v5-6-2abe2bb9cdbc@nexthop.ai> References: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> In-Reply-To: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> To: Rob Herring , Saravana Kannan , Frank Rowand Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784776787; l=1186; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=7hLPGvySNdkYHchBXO/iRfhwHDLyA7Ot2MizQ13r8lI=; b=O1vzPq1Zk8CW30n6MTqPJMAIqb7Q8PJ3+bpSau8MJSsXkYusku5/ZDR+xeUd74z3KaBLq+9uo BbFlLYUrm9qApVK/bj/UiNw7tBdVoMs6EgmSzezPhLy67hUj6d64B2j X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= dup_and_fixup_symbol_prop() rewrites a symbol value by replacing its "/fragment/__overlay__" prefix with the fragment's target path. When the fragment targets the root node the target path is "/" and the result starts with "//", which __of_find_node_by_full_path() cannot resolve: symbols pointing into such fragments silently stop resolving. Drop the target path when it is the root. Fixes: d1651b03c2df ("of: overlay: add overlay symbols to live device tree") Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Abdurrahman Hussain --- drivers/of/overlay.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index f1aa8574069a..c6962e9948cc 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -256,6 +256,9 @@ static struct property *dup_and_fixup_symbol_prop( if (!target_path) return NULL; target_path_len =3D strlen(target_path); + /* a root target renders as "/"; drop it to avoid "//" results */ + if (target_path_len =3D=3D 1 && target_path[0] =3D=3D '/') + target_path_len =3D 0; =20 new_prop =3D kzalloc_obj(*new_prop); if (!new_prop) --=20 2.54.0 From nobody Fri Jul 24 05:26:19 2026 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 BD8D033C536 for ; Thu, 23 Jul 2026 03:19:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776812; cv=none; b=Cf5UPx0sKWcKqMMEnIpD9ZjcoKBz303i3whzWq1Cqwvb0t8E037QfEuYsms4F+FTtoxegwK0IoX0aNtmwYdc2U4bkKiGmpBYgdZ2BzVLA200z3zV+aQE63VGNwUvbcbILS+P3jbGODXTfOH4K4Z8lwy775YOQNSlLeA9jdhNnYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776812; c=relaxed/simple; bh=dNyq0gHVNROKupjvqrJOvTkgnMbbqscYff0AMbsn6hU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FnErKogR7DnqDEAx98h9rPyjN0fIi0JstmUyl/cuE0LaVMQwXJYtlrwzMr10FCEtaVPNXNi5Um+83i2jxom0hlqt9aSGUvD646dKKB9YELBy02o0Qi2BDFEyY1eroN/7PGLOrRsZ/uqwp1xoplNh3c6caJHFiuyckcAPp9UNdtA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=kQ4BU915; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="kQ4BU915" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-c99eaa1f020so180069a12.2 for ; Wed, 22 Jul 2026 20:19:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1784776795; x=1785381595; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ayHuk5PnsCTzmn51E1l8BC7HjdIcsF327JBpGTA4oZY=; b=kQ4BU9151vu9LSDMyOdY74diyZNgSHQyoZCClQw5pJd1RDJCpYC7UcTB94fBQVot7C 7J4sAs0RYrw6mk8IcBZsunZWmCqT4hJb3PsIuc/Q4jQpwLD9qilVlYhJm7rT6qprdRXY MVML5eKS1aFLQ1dnxY6wUbBSZe/zEf1pwMRf7R/S/Z56wV4sV/qtbKi9ChxLpE7NURdg BdEBwnU3p7X2WRe2HSlQwf+ovyWM8EnHnpL5CltdUJt2gE7vaz/JxolZlyFd6/+6P/gm VT2GVWRpUMLifrX2qMEqNOGdblC8mnYSFck2V0SqFntHPLpdcWZalLBL/eBXtXSAXx5A 2ZcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784776795; x=1785381595; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ayHuk5PnsCTzmn51E1l8BC7HjdIcsF327JBpGTA4oZY=; b=BMvfol0ETZWqA1B/Mvi8fHCkO1+FV208TWGBsg4v3mOdfkIuFawheBV7R4OTqghH2Y +5nnI+hQQdPdsI6YUpA7thQIUQofYekVcIVEVLhahQZ2BHwxpTGR1D0yz09uYkrzO6X6 aP8diIYXYbXPhggD70sePUOseJXTKt3mw+Tfm+J0as4qx3Da9ungCNljHkqexZHQJQUC n2PGK+X2X1b6KL2BGBSBkwQN7oq+2WRqnZjPCUsEEM6Yobb/J9PA3ocRZ4QkqDsj7nhc rWyyPhDNocd0Flz+HmDXZMTnRLfgEogOQOcziUJhJiRxqBgIMMODDMqoiQBmtKfOoqc+ +d8A== X-Forwarded-Encrypted: i=1; AHgh+Rqf0g4/YtIhUg3SR6LY27mmN2sz9W4dNYE+9rm1zcBCqxi1VKyrQE8vDqgPiOF87j+pWqPVM8yUfiAgAHU=@vger.kernel.org X-Gm-Message-State: AOJu0YwVXSoxqoaORnH349avnqoLUYZG98nhGWpxvWTS7nyhqMgVhEy0 8i/e13mq8ouTR9N5oe1J03Bm636+lkJE1EWHds/MrQE2g67/YQXNvxmpkcGWoSz5i9c= X-Gm-Gg: AR+sD11kyGASBmR92guQI9qlUZjxmKiSryc31+vhqVXMuQRXBD1O+t4JcjRsiQJFtUo 7HxPfxRc6uJazTNVIlrXYFKG9gL62f7z3Qzxi8wockbbIIXDGLTYNSqS4bZ+LhyALEzlOxFJw/L DzgvvBjQ80WjF1x+a+Lj/GfqNeu5NM3+Ah1Gq9MPaKfSjVbZgQ7UZVhLoz2MIw0mPrU0S9uVYOX mirBxqZgOSFlVINFtcQRlf1V1suSEcb3JKNPxYz8XyBtdPJP5YIIRToiG4kI6F+D5WkeP0sNSE1 ZRezY1l9u1/48sHQgXkPkw+6qDZz8H4ZBJwi0H0EN7bvGAArywRCaHn8TKh5av66L4UxnZaXFWG BLMrKOIyN6Bfb3AvqnXXO32Uo8ZIWu/CK1TMLfn9xnwRKqbT7aS5wKY8t+QBZ/Ktx5zaoEQYFnh k1uisf X-Received: by 2002:a05:6a20:160e:b0:3bf:6237:b1b3 with SMTP id adf61e73a8af0-3c44b18ab60mr1411395637.42.1784776794761; Wed, 22 Jul 2026 20:19:54 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147e1bc886sm13826080eec.26.2026.07.22.20.19.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 20:19:54 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 22 Jul 2026 20:19:48 -0700 Subject: [PATCH v5 7/9] of/overlay: return ERR_PTR from dup_and_fixup_symbol_prop() 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: <20260722-nh-of-alias-overlay-v5-7-2abe2bb9cdbc@nexthop.ai> References: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> In-Reply-To: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> To: Rob Herring , Saravana Kannan , Frank Rowand Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784776787; l=4346; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=dNyq0gHVNROKupjvqrJOvTkgnMbbqscYff0AMbsn6hU=; b=kC5kSAp5GOx2zMzvch84da8f2mlE9W0fNMOUFW9mtXRM/LCfA7FlSN3ILaTVe6KfBg1IVE57x EyUbhk1D+9HC3nU0X5UmZXh5OYjPZZBMD52czBWnqQ8I/DLt1kOxsAH X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= dup_and_fixup_symbol_prop() returns NULL for malformed values, for values that are not paths into one of the overlay's fragments, and for allocation failures. The caller reports all of them as -ENOMEM, so a structural problem in /__symbols__ is diagnosed as memory exhaustion. A later patch reuses the helper for /aliases values and must handle the three cases differently: copy verbatim, warn, or fail the apply. Return ERR_PTR(-EINVAL), ERR_PTR(-ENODEV) and ERR_PTR(-ENOMEM) respectively and propagate the errno in the /__symbols__ caller. Also verify that the value descends through the matched fragment's __overlay__ node before cutting the prefix. Only the first path component was resolved, so an absolute live-tree value sharing its first component with a fragment name was sliced at the prefix length and rewritten to garbage. A prefix mismatch returns -ENODEV. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Abdurrahman Hussain --- drivers/of/overlay.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index c6962e9948cc..1a2df83fbd8d 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -206,6 +206,10 @@ static void overlay_fw_devlink_refresh(struct overlay_= changeset *ovcs) * The duplicated property value will be modified by replacing the * "/fragment_name/__overlay/" portion of the value with the target * path from the fragment node. + * + * Return: the fixed-up property, or ERR_PTR: -EINVAL if @prop's value + * is not a valid non-empty C string, -ENODEV if it is not a path into + * one of @ovcs's fragments, -ENOMEM on allocation failure. */ static struct property *dup_and_fixup_symbol_prop( struct overlay_changeset *ovcs, const struct property *prop) @@ -217,6 +221,8 @@ static struct property *dup_and_fixup_symbol_prop( const char *path; const char *path_tail; const char *target_path; + char *overlay_name; + bool mismatch; int k; int overlay_name_len; int path_len; @@ -224,14 +230,14 @@ static struct property *dup_and_fixup_symbol_prop( int target_path_len; =20 if (!prop->value) - return NULL; + return ERR_PTR(-EINVAL); if (strnlen(prop->value, prop->length) >=3D prop->length) - return NULL; + return ERR_PTR(-EINVAL); path =3D prop->value; path_len =3D strlen(path); =20 if (path_len < 1) - return NULL; + return ERR_PTR(-EINVAL); fragment_node =3D __of_find_node_by_path(ovcs->overlay_root, path + 1); overlay_node =3D __of_find_node_by_path(fragment_node, "__overlay__/"); of_node_put(fragment_node); @@ -243,18 +249,27 @@ static struct property *dup_and_fixup_symbol_prop( break; } if (k >=3D ovcs->count) - return NULL; + return ERR_PTR(-ENODEV); + + overlay_name =3D kasprintf(GFP_KERNEL, "%pOF", fragment->overlay); + if (!overlay_name) + return ERR_PTR(-ENOMEM); + overlay_name_len =3D strlen(overlay_name); =20 - overlay_name_len =3D snprintf(NULL, 0, "%pOF", fragment->overlay); + /* @path must descend through this fragment's __overlay__ node */ + mismatch =3D overlay_name_len > path_len || + strncmp(path, overlay_name, overlay_name_len) !=3D 0 || + (path[overlay_name_len] !=3D '/' && path[overlay_name_len]); + kfree(overlay_name); + if (mismatch) + return ERR_PTR(-ENODEV); =20 - if (overlay_name_len > path_len) - return NULL; path_tail =3D path + overlay_name_len; path_tail_len =3D strlen(path_tail); =20 target_path =3D kasprintf(GFP_KERNEL, "%pOF", fragment->target); if (!target_path) - return NULL; + return ERR_PTR(-ENOMEM); target_path_len =3D strlen(target_path); /* a root target renders as "/"; drop it to avoid "//" results */ if (target_path_len =3D=3D 1 && target_path[0] =3D=3D '/') @@ -284,7 +299,7 @@ static struct property *dup_and_fixup_symbol_prop( err_free_target_path: kfree(target_path); =20 - return NULL; + return ERR_PTR(-ENOMEM); } =20 /** @@ -353,6 +368,8 @@ static int add_changeset_property(struct overlay_change= set *ovcs, if (prop) return -EINVAL; new_prop =3D dup_and_fixup_symbol_prop(ovcs, overlay_prop); + if (IS_ERR(new_prop)) + return PTR_ERR(new_prop); } else { new_prop =3D __of_prop_dup(overlay_prop, GFP_KERNEL); } --=20 2.54.0 From nobody Fri Jul 24 05:26:19 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 680CF364043 for ; Thu, 23 Jul 2026 03:19:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776801; cv=none; b=D92pWdadN9UGMBRHXhAh/6G1H+jiL6OQw038cWfAAwtMz6GpkFNOkhd6yRerb5vXYxQ0TS7JWAV2FUIPs23ij2ywxLvShKZI73ol1slWX5MJjwINqYz3qyUlb4Kioe8S64yXIRMe3S16GfagMm8DG5xJOy+xOkXIAPFRUdzeE/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776801; c=relaxed/simple; bh=q6Ij35o5ZF2RoKcxwQYgmY5XfSWE46siWFJxO/TKcaM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=e19M4OmfLYzwEXu+nI1chG3J1YHr+njbkITnT0TC1id9R1ehHEwZljwr3u2HfXw4qQFvZQJoNhtDUL3SShzgYKAwxGXroZpuHl79b1V4YZ4gN52rYlNlD+L4xu9Vqj6Ys7zVcpHFCOOdBcHSyJf2AI70y5HBm5bDMfYDpQvdja8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=NOmFCbdx; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="NOmFCbdx" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2ce87c7e3bbso2176785ad.1 for ; Wed, 22 Jul 2026 20:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1784776796; x=1785381596; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=RzjRD582rf+tZhKKl0DwhMekWNlTzSLHfavCOSotFVo=; b=NOmFCbdx5HA/6B7iLDizqTmG1RdzxdL30SyJnzwW26EW5738nm1bNO+b3a2WXeK5Qq mo4uSPCItiqat3HUVhu4ni2sF7phfkqcTRuAOLW2j+tE+F+5TUWiQtTzDazxBkJqdjhX G4zxPpLd4v05KJGv1L2Ahzz4+OvGsYKHKSwcIhCTxKyFPMd6VAHGAPQrNabqzUJ5e6/w 1VrnR5fghqhUxKUYgsQtph1KXF10DzZlJCAOPmBMQpM41eCoEZgcXJSxGsRoaOySuL00 E1QzGaikBJMY/UvcriZLxyCWEszBedov2tQU9uU/Ti1F59PZLHiwXf934ueQld15xjUr umEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784776796; x=1785381596; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=RzjRD582rf+tZhKKl0DwhMekWNlTzSLHfavCOSotFVo=; b=ksz+WFuFYHunECfgOdt6aaRRhyIKEtQ1/o3+4t6FkNGFMsb8tGZiv0abyRce+utpXV Eyc4i8Tkog5PvVf809YrAwKV0AZoCnoxnFhEQlZGuDalgcyoHACi5mmDVYqq8HTvPlX3 9bB7UHsdFcoKbG2DOsq8KV8ur4+xEn/7gRV9PxoYhPsVYCG0PCA2lu6kUH1nB/KuEtbx /e21MqkbDQa1wNOeIq2aGNGmYE7fo9dK3ceTj68nn3ksBpf3tIwEQPwR3OEMx9PQnDnE JygwwGfUeIBg+L4uTbxBk5mFaOCVS6xWL2JO5DuXS89G1CRA/LA7vX9GBE1TcsiE80do Zgag== X-Forwarded-Encrypted: i=1; AHgh+RqXBAJCPxr3+hwrwqlBQY87W+TPf0EjKu0OWrH0A7b/jMJo1DoVku0HnjSJV4PoqjHTWme2vof/jbOP41Y=@vger.kernel.org X-Gm-Message-State: AOJu0YyWGQje3nnBjUziFhauJpVldJp0FkJv4ERAO5Haoum5u7tR7ZhT QvxPPg7Z+oK/F8DvjYmygURM8xiiyae209WWnEECNuSDIP4vPnMl/WbpCyMIKp/3aoM= X-Gm-Gg: AR+sD11GXU9DRsljMM+EcAtBJPFowI+u15qE+Z7jR97K3mN8q9705xum1LPktbdjW6p 9bgzeWlVWbnkVvyRlz+8PtIBGq5T8Fu9uHdN1Yk0SH5ozlcrOyqpCwBk7qAus7rNLgdDXD7Z45e DSyDzNzGOoRziFihWlDluMK5VUIJ5Q7LGIVpCMyvKRwYFWBbdexroFQuJI64pEKzrt3xvrG4PJT QX6Q4R9eDxIMWztelAcdMGL/CmfkTORAIfsFs9ziminNGw2bMENCki4LGHKvDY4Hi6Wx6+tJccB GyngBtpswVPAZyCT/6PdMkxFwVEhrodfyDWjCkJYm98XiYeL1yWdIoAYF/AulGJfCZC4AQyKyNW y0WJ5e1oEwUHVH97rggnQV7vCra0WBbIeqbUT/5y7b8dnScM1bl033fxwmvbSjFRXmp5tPsM4CU ASrVW/7KTBC3h+oRo= X-Received: by 2002:a05:6a20:9395:b0:3c3:a41f:ce7d with SMTP id adf61e73a8af0-3c44ac1e447mr1413048637.0.1784776795756; Wed, 22 Jul 2026 20:19:55 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147e1bc886sm13826080eec.26.2026.07.22.20.19.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 20:19:55 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 22 Jul 2026 20:19:49 -0700 Subject: [PATCH v5 8/9] of/overlay: rewrite /aliases path values to live-tree paths 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: <20260722-nh-of-alias-overlay-v5-8-2abe2bb9cdbc@nexthop.ai> References: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> In-Reply-To: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> To: Rob Herring , Saravana Kannan , Frank Rowand Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784776787; l=2368; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=q6Ij35o5ZF2RoKcxwQYgmY5XfSWE46siWFJxO/TKcaM=; b=zAkNSh7AWDUONPU7sflGorFo4ckNjJges57JQcGrst2yYNGaUu692PyxLI2RslsXCsum/QbK9 7FuJ+GVWKl+AhMkjdc71+mnpcASxkaKpT4ReirNI4b2gddw9bnnEK1E X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= An /aliases property added by an overlay references labeled nodes as "&label", which dtc renders as an overlay-internal path such as "/fragment@1/__overlay__/i2c@40000". The value is copied verbatim into the live tree, of_find_node_by_path() cannot resolve it, and of_alias_get_id() keeps returning -ENODEV. /__symbols__ values follow the same convention and are already rewritten by dup_and_fixup_symbol_prop(). Use it for properties of the /aliases node too: - a value that resolves inside one of the overlay's fragments is stored rewritten to the live-tree path - -ENODEV (legacy string aliases, absolute live-tree paths) is copied verbatim, as before this series - -EINVAL (not a NUL-terminated string) is copied verbatim with a warning; consumers validate before dereferencing, and an overlay that applied before this series keeps applying - only -ENOMEM fails the apply Pseudo-properties are exempt: the is_pseudo_property() check at the top of add_changeset_property() only covers live-tree targets, and a phandle of a newly created /aliases node is a cell, not a string. Assisted-by: Claude:claude-fable-5 [Claude Code] Signed-off-by: Abdurrahman Hussain --- drivers/of/overlay.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 1a2df83fbd8d..27a460daeed9 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -370,6 +370,19 @@ static int add_changeset_property(struct overlay_chang= eset *ovcs, new_prop =3D dup_and_fixup_symbol_prop(ovcs, overlay_prop); if (IS_ERR(new_prop)) return PTR_ERR(new_prop); + } else if (!is_pseudo_property(overlay_prop->name) && + of_node_is_aliases(target->np)) { + /* rewrite overlay-internal alias values to live-tree paths */ + new_prop =3D dup_and_fixup_symbol_prop(ovcs, overlay_prop); + if (new_prop =3D=3D ERR_PTR(-ENOMEM)) + return -ENOMEM; + if (IS_ERR(new_prop)) { + if (new_prop =3D=3D ERR_PTR(-EINVAL)) + pr_warn("%pOF/%s is not a valid string; alias will be inert\n", + target->np, overlay_prop->name); + /* not overlay-internal: copy verbatim, consumers validate */ + new_prop =3D __of_prop_dup(overlay_prop, GFP_KERNEL); + } } else { new_prop =3D __of_prop_dup(overlay_prop, GFP_KERNEL); } --=20 2.54.0 From nobody Fri Jul 24 05:26:19 2026 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 8513B3644DE for ; Thu, 23 Jul 2026 03:19:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776807; cv=none; b=EgFsIbBAtcmLz678rp7eAm5MKlAaOyoYsLKlx+/tVmFB5AseW78Et8nHLRFZXYzDRQYwvsZ3qWWvgzhRCiMQGytYPmUpS8Y/GePjzlZzlbKWfiWYqbA5PwYXj90FHikvbHcv14OOdrIDurPXd/TNOev5YSV5Ihd3OpfOoKdZBvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784776807; c=relaxed/simple; bh=rtMHX9hWMpcieCzh+lEL0bv+hah6KKo01VRR5TnIRxg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aAawRLe9TLhRNlL0IXKPTuGHrU1kfsLWLQ3/rGk0PAk3ApWLlPHl9TkWHrZnXxd7V4LgEgFY1tfeo6dLaScfTUD2WhBVXQKdja3aS/18N1m8/U/+SOJByfKr8+6/sW2vA4cFFbNuVi6fYBjUCky45xK3ORw4DlKdvnON9yQwUvY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai; spf=pass smtp.mailfrom=nexthop.ai; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b=MygdN7k+; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nexthop.ai Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nexthop.ai header.i=@nexthop.ai header.b="MygdN7k+" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2cc7e86e7aeso1893935ad.2 for ; Wed, 22 Jul 2026 20:19:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nexthop.ai; s=google; t=1784776797; x=1785381597; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=OBfNFbSVh1FYGWwWZzjs3Er9OcgI7SYTXtrFRcmH5Do=; b=MygdN7k+d7Dn0nRcGBCK/3LT5vk6J+9DjQJ+5f8YKCbZz/NUOVjHQuSZab8YRB7iOI c77rSNI+qwt8xox5Hk4Ww7clc1raHOz9rSLzyz/zp+WSG3vMcTgJW3/IJkeGiPMP6+9L 9t558mnYKc7P2TQhlQqHJOldz+D46awimLfwSPm1aZ/ufM2JEIuV2yupW2zPWDEjkhqj V82IfaZwVumZn4cthYNhPghT3Bs1dqfyVQCzRIcRoPJKgtN0NLXDczCNr4e/6kX3QgS6 +szWSIZ9HUjF3zpcIuscGTd0nIwzVCp9F3KXDrTeI7E1GAh4ixfiZ6qlkx5HkK/U69G9 iHFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784776797; x=1785381597; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=OBfNFbSVh1FYGWwWZzjs3Er9OcgI7SYTXtrFRcmH5Do=; b=i243VtB0YHckRJ3OwW+HLyODdUg3ZGcczI8k2BKyp7Mk/6SQlyFUrsQjiY14Xk7JeP NO2PbdLBah5JafApRawPkHQ/2AcmDb9Ij9UbHiAYZEgW2SmZmARtxsrGcn2ZC6dFd4kW WRrG/JH1fxchZ0zxMaseMZAh0BIEvIPVUiiutSVK0qGzrQvGSt6+uzyxQBX5FC5z8WUF EIkAiulyCRTWaBb5zWbUIloGB2zdjucLBJB/qkOi1kGOm9baKZHw+IrAz63/hP6xaWx9 RQqDiGdy1Ag7iQz3t+5LP5VOGV2FQSUiYKaskPvyusrpaOhpBgWvoZ4A37w4PirCZGms rjgQ== X-Forwarded-Encrypted: i=1; AHgh+Rotg+Qd8LRNmStVLxaooV2KHm7lP4n557QVTvZElShlHW81KUCVyAfwWjuQTxYQ6z7YMSadjFHZZ4hxIqo=@vger.kernel.org X-Gm-Message-State: AOJu0YxHMHe+KRgRmdYjnz0x6zTeF9c3CR9dryGtepIiulQ0fkAOY6za zuhBfgW5JRnU8yreqtZN6rE1KA18dLmct/bP0/BzhjO6YZLik8XfNLcCyFXdzL3puC4= X-Gm-Gg: AR+sD10LMYVxcbZLmTBGEruFyTviuIP/qNVGJzyi3Itt3qx4gfW3kw4uxQZYWIQsAPQ qPNJ+YIruMXJWeEtM9hRx9FCnUwspf/IyMbCd3YuJHOF631HheIz6p5OzcwWfnpevD2wJzthKSu vAqbnzZyHogE2Rnss3lJZfpRu/dgq1bDOHlARiCLiE/JAyfOUCbWbqyP7o4lzFwj5wNYWIGXvWR mh0paN7lxeze8OYAka7yO3clr5EBv0Wx0gxgqrvK5qoZscPUwrqaabymDQIHQcMTAuTSXvwyCG/ bQ+HK1iUxcb1eKRPVPnA4Bw9tDXr/wqehjtGgT4GrvlZT3/Oka9PQo3ucruL3+pcX/0BMpv88pR jUKa4NohrFzwNRvB6UEELk46ubhDpJol+uTZatcQAlH3I1q1javUumyAgeUg9FORjd+F+CDqlVh hXJqkEba35ii3CvzE= X-Received: by 2002:a05:6a20:734b:b0:3c0:b766:750c with SMTP id adf61e73a8af0-3c44b24d3b9mr1322097637.58.1784776796832; Wed, 22 Jul 2026 20:19:56 -0700 (PDT) Received: from [127.0.0.2] ([50.145.100.174]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3147e1bc886sm13826080eec.26.2026.07.22.20.19.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2026 20:19:56 -0700 (PDT) From: Abdurrahman Hussain Date: Wed, 22 Jul 2026 20:19:50 -0700 Subject: [PATCH v5 9/9] of: unittest: cover /aliases updates from overlay apply/revert 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: <20260722-nh-of-alias-overlay-v5-9-2abe2bb9cdbc@nexthop.ai> References: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> In-Reply-To: <20260722-nh-of-alias-overlay-v5-0-2abe2bb9cdbc@nexthop.ai> To: Rob Herring , Saravana Kannan , Frank Rowand Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Abdurrahman Hussain X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784776787; l=6079; i=abdurrahman@nexthop.ai; s=20260510; h=from:subject:message-id; bh=rtMHX9hWMpcieCzh+lEL0bv+hah6KKo01VRR5TnIRxg=; b=u4muQ98YCHoyue5Up82bPt0OOkTbg5FAVJ+0WbGjEqQcvVwhGgdFBFq5ZilJF9RncXLqUkH1M Z0ckzxDmbl1C1WWUUdwHbRRVhp0Ob8l9js3oisXm/oKDaP9GUFaKauN X-Developer-Key: i=abdurrahman@nexthop.ai; a=ed25519; pk=omTm9cCAbO0ZhS32aKfJDKue0W3sQGpG9ub5eYHif8I= Add overlay_alias.dtso and of_unittest_overlay_alias(). The overlay has two fragments: target-path=3D"" grafts a labeled node under the run-time target base, and target-path=3D"/aliases" adds `testcase-alias99 =3D &