of: property: Fix potential firmware node reference's argument count got out of range
Subsystems (4)
v4 cover of: property: Fix potential firmware node reference's argument count got out of range
This patch series is to fix an OF issue below:
The firmware node reference argument count @args->nargs got by of_fwnode_get_reference_args() may be out of range.
---
Changes in v4:
- Correct commit message for patch 1/2
- Add one more patch 2/2 to align both macros
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Remove RFC, correct title and commit message.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Increase macro @NR_FWNODE_REFERENCE_ARGS to align with @MAX_PHANDLE_ARGS.
- Correct fix tag and send as RFC patch.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Zijun Hu (2):
of: property: Increase NR_FWNODE_REFERENCE_ARGS
of: Align macro MAX_PHANDLE_ARGS with NR_FWNODE_REFERENCE_ARGS
include/linux/fwnode.h | 2 +- include/linux/of.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
---
base-commit: cd726b80a9b2e35397f3f4ecd845a8fd247ee79e
change-id: 20250114-fix_arg_count-73feae90fccb
Best regards,
Signature · 1 line
Zijun Hu <[email protected]>
PATCH v4 1/2 of: property: Increase NR_FWNODE_REFERENCE_ARGS
From: Zijun Hu <[email protected]>
Currently, the following two macros have different values:
// The maximal argument count for firmware node reference
#define NR_FWNODE_REFERENCE_ARGS 8
// The maximal argument count for DT node reference
#define MAX_PHANDLE_ARGS 16
It may cause firmware node reference's argument count out of range if directly assign DT node reference's argument count to firmware's.
drivers/of/property.c:of_fwnode_get_reference_args() is doing the direct assignment, so may cause firmware's argument count @args->nargs got out of range, namely, in [9, 16].
Fix by increasing NR_FWNODE_REFERENCE_ARGS to 16 to meet DT requirement. Will align both macros later to avoid such inconsistency.
--- include/linux/fwnode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/fwnode.h +1 -1
@@ -91,7 +91,7 @@ struct fwnode_endpoint {#define SWNODE_GRAPH_PORT_NAME_FMT "port@%u"#define SWNODE_GRAPH_ENDPOINT_NAME_FMT "endpoint@%u" -#define NR_FWNODE_REFERENCE_ARGS 8 +#define NR_FWNODE_REFERENCE_ARGS 16/** * struct fwnode_reference_args - Fwnode reference with additional arguments
Signature · 1 line
2.34.1
Re: [PATCH v4 1/2] of: property: Increase NR_FWNODE_REFERENCE_ARGS
Quoted 16 lines · Zijun Hu
From: Zijun Hu <[email protected]>
Currently, the following two macros have different values:
// The maximal argument count for firmware node reference
#defineNR_FWNODE_REFERENCE_ARGS8
// The maximal argument count for DT node reference
#defineMAX_PHANDLE_ARGS16It may cause firmware node reference's argument count out of range if directly assign DT node reference's argument count to firmware's.
drivers/of/property.c:of_fwnode_get_reference_args() is doing the direct assignment, so may cause firmware's argument count @args->nargs got out of range, namely, in [9, 16].
Quoted 5 lines
Fix by increasing
NR_FWNODE_REFERENCE_ARGSto 16 to meet DT requirement. Will align both macros later to avoid such inconsistency.Fixes 3e3119d3088f ("device property: Introduce fwnode_property_get_reference_args")Signed-off-by Zijun Hu <[email protected]>
Signature · 1 line
Sakari Ailus
PATCH v4 2/2 of: Align macro MAX_PHANDLE_ARGS with NR_FWNODE_REFERENCE_ARGS
In reply to Zijun HuFrom: Zijun Hu <[email protected]>
Macro NR_FWNODE_REFERENCE_ARGS defines the maximal argument count for firmware node reference, and MAX_PHANDLE_ARGS defines the maximal argument count for DT node reference, both have the same value now.
To void argument count inconsistency between firmware and DT, simply align both macros by '#define MAX_PHANDLE_ARGS NR_FWNODE_REFERENCE_ARGS'.
--- include/linux/of.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/of.h +1 -1
@@ -67,7 +67,7 @@ struct device_node {#endif }; -#define MAX_PHANDLE_ARGS 16 +#define MAX_PHANDLE_ARGS NR_FWNODE_REFERENCE_ARGSstruct of_phandle_args {struct device_node *np;int args_count;
Signature · 1 line
2.34.1
Re: [PATCH v4 2/2] of: Align macro MAX_PHANDLE_ARGS with NR_FWNODE_REFERENCE_ARGS
Quoted 8 lines · Zijun Hu
From: Zijun Hu <[email protected]>
Macro
NR_FWNODE_REFERENCE_ARGSdefines the maximal argument count for firmware node reference, andMAX_PHANDLE_ARGSdefines the maximal argument count for DT node reference, both have the same value now.To void argument count inconsistency between firmware and DT, simply align both macros by '#define
MAX_PHANDLE_ARGSNR_FWNODE_REFERENCE_ARGS'.
I would add here that the of.h includes fwnode.h already, so it doesn't add any new compile time dependency.
Both patches LGTM,
Signature · 2 lines
With Best Regards, Andy Shevchenko
Sakari Ailus
reviewerRe: [PATCH v4 2/2] of: Align macro MAX_PHANDLE_ARGS with NR_FWNODE_REFERENCE_ARGS
Hi Andy, Zijun,
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Zijun Hu
From: Zijun Hu <[email protected]>
Macro
NR_FWNODE_REFERENCE_ARGSdefines the maximal argument count for firmware node reference, andMAX_PHANDLE_ARGSdefines the maximal argument count for DT node reference, both have the same value now.
Quoted 5 lines
Quoted 2 lines
To void argument count inconsistency between firmware and DT, simply align both macros by '#define
MAX_PHANDLE_ARGSNR_FWNODE_REFERENCE_ARGS'.I would add here that the
of.hincludesfwnode.halready, so it doesn't add any new compile time dependency.
It's included via property.h but I think that's fine.
Quoted 3 lines
Both patches LGTM,
Acked-by Andy Shevchenko <[email protected]>
Signature · 1 line
Sakari Ailus
Re: [PATCH v4 2/2] of: Align macro MAX_PHANDLE_ARGS with NR_FWNODE_REFERENCE_ARGS
In reply to Andy ShevchenkoQuoted 3 lines · Andy Shevchenko
I would add here that the
of.hincludesfwnode.halready, so it doesn't add any new compile time dependency.
thank you Andy for comments.
include/linux/of.h:
struct device_node {
...
struct fwnode_handle fwnode; // this type is defined by fwnode.h
...
}
include/linux/fwnode.h:
struct fwnode_handle {...}
So of.h must include fwnode.h
Perhaps, of.h needs to include fwnode.h *explicitly* even if this is another topic.
Quoted 2 lines
Both patches LGTM,
Acked-by Andy Shevchenko <[email protected]>
Re: [PATCH v4 2/2] of: Align macro MAX_PHANDLE_ARGS with NR_FWNODE_REFERENCE_ARGS
In reply to Zijun HuQuoted 10 lines · Zijun Hu
From: Zijun Hu <[email protected]>
Macro
NR_FWNODE_REFERENCE_ARGSdefines the maximal argument count for firmware node reference, andMAX_PHANDLE_ARGSdefines the maximal argument count for DT node reference, both have the same value now.To void argument count inconsistency between firmware and DT, simply align both macros by '#define
MAX_PHANDLE_ARGSNR_FWNODE_REFERENCE_ARGS'.Signed-off-by Zijun Hu <[email protected]>
Signature · 1 line
Sakari Ailus