Skip to content

Commit ef69d74

Browse files
gauravminochaosglikely
authored andcommitted
of: Disabling OF functions that use sysfs if CONFIG_SYSFS disabled
This patch is to the fix the recent runtime bug in kernel reported by <fengguang.wu@intel.com>. The bug was exposed by commit b951f9d, "Enabling OF selftest to run without machine's devicetree" and is exposed when CONFIG_OF_SELFTEST is enabled and CONFIG_SYSFS is disabled. Mail Subject: [OF test] BUG: unable to handle kernel NULL pointer dereference at 00000038 Tested on x86 and arm architecture Signed-off-by: Gaurav Minocha <gaurav.minocha.os@gmail.com> Signed-off-by: Grant Likely <grant.likely@linaro.org>
1 parent 5f74d8b commit ef69d74

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎drivers/of/base.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ int __of_add_property_sysfs(struct device_node *np, struct property *pp)
138138
/* Important: Don't leak passwords */
139139
bool secure = strncmp(pp->name, "security-", 9) == 0;
140140

141+
if (!IS_ENABLED(CONFIG_SYSFS))
142+
return 0;
143+
141144
if (!of_kset || !of_node_is_attached(np))
142145
return 0;
143146

@@ -158,6 +161,9 @@ int __of_attach_node_sysfs(struct device_node *np)
158161
struct property *pp;
159162
int rc;
160163

164+
if (!IS_ENABLED(CONFIG_SYSFS))
165+
return 0;
166+
161167
if (!of_kset)
162168
return 0;
163169

@@ -1713,6 +1719,9 @@ int __of_remove_property(struct device_node *np, struct property *prop)
17131719

17141720
void __of_remove_property_sysfs(struct device_node *np, struct property *prop)
17151721
{
1722+
if (!IS_ENABLED(CONFIG_SYSFS))
1723+
return;
1724+
17161725
/* at early boot, bail here and defer setup to of_init() */
17171726
if (of_kset && of_node_is_attached(np))
17181727
sysfs_remove_bin_file(&np->kobj, &prop->attr);
@@ -1777,6 +1786,9 @@ int __of_update_property(struct device_node *np, struct property *newprop,
17771786
void __of_update_property_sysfs(struct device_node *np, struct property *newprop,
17781787
struct property *oldprop)
17791788
{
1789+
if (!IS_ENABLED(CONFIG_SYSFS))
1790+
return;
1791+
17801792
/* At early boot, bail out and defer setup to of_init() */
17811793
if (!of_kset)
17821794
return;

‎drivers/of/dynamic.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ void __of_detach_node_sysfs(struct device_node *np)
4545
{
4646
struct property *pp;
4747

48+
if (!IS_ENABLED(CONFIG_SYSFS))
49+
return;
50+
4851
BUG_ON(!of_node_is_initialized(np));
4952
if (!of_kset)
5053
return;

0 commit comments

Comments
 (0)