media: ipu3-cio2: support multiple sensors and VCMs with HID name
Subsystems (2)
PATCH 1/1 media: ipu3-cio2: support multiple sensors and VCMs with HID name
From: Bingbu Cao <[email protected]>
In current cio2-bridge, it is using the hid as node name to register software node and swnode will create kobject and sysfs entry with the node name, if there are multiple sensors and VCMs which are sharing same HID name, it will cause the software nodes registration failure:
[ 7.142311] sysfs: cannot create duplicate filename '/kernel/software_nodes/dw9714' ... [ 7.142328] Call Trace: [ 7.142330] <TASK> [ 7.142336] dump_stack_lvl+0x49/0x63 [ 7.142341] dump_stack+0x10/0x16 [ 7.142343] sysfs_warn_dup.cold+0x17/0x2b [ 7.142346] sysfs_create_dir_ns+0xbc/0xd0 [ 7.142351] kobject_add_internal+0xb1/0x2b0 [ 7.142356] kobject_init_and_add+0x71/0xa0 [ 7.142360] swnode_register+0x136/0x210 [ 7.142363] software_node_register+0xd2/0x120 [ 7.142364] software_node_register_nodes+0x83/0xf0 [ 7.142366] ? acpi_get_physical_device_location+0x65/0xc0 [ 7.142371] cio2_bridge_init+0x82a/0xb5e ... [ 7.142448] kobject_add_internal failed for dw9714 with -EEXIST,
don't try to register things with the same name in the same directory.
One solution is appending the sensor link(Mipi Port) in SSDB as suffix of the node name to fix this problem.
--- drivers/media/pci/intel/ipu3/cio2-bridge.c | 14 ++++++++++---- drivers/media/pci/intel/ipu3/cio2-bridge.h | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-)
drivers/media/pci/intel/ipu3/cio2-bridge.c +10 -4
@@ -212,6 +212,7 @@ static void cio2_bridge_create_connection_swnodes(struct cio2_bridge *bridge, struct cio2_sensor *sensor) {struct software_node *nodes = sensor->swnodes; +char vcm_name[ACPI_ID_LEN +4 ];cio2_bridge_init_swnode_names (sensor);
@@ -229,9 +230,12 @@ static void cio2_bridge_create_connection_swnodes(struct cio2_bridge *bridge, sensor->node_names.endpoint, &nodes[SWNODE_CIO2_PORT ], sensor->cio2_properties); -if (sensor->ssdb.vcmtype) - nodes[SWNODE_VCM ] = -NODE_VCM (cio2_vcm_types[sensor->ssdb.vcmtype -1 ]); +if (sensor->ssdb.vcmtype) { +scnprintf (vcm_name,sizeof (vcm_name),"%s-%u" , + cio2_vcm_types[sensor->ssdb.vcmtype -1 ], + sensor->ssdb.link); + nodes[SWNODE_VCM ] =NODE_VCM (vcm_name); + }cio2_bridge_init_swnode_group (sensor); }
@@ -295,7 +299,6 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg, } sensor = &bridge->sensors[bridge->n_sensors]; -strscpy (sensor->name, cfg->hid,sizeof (sensor->name)); ret = cio2_bridge_read_acpi_buffer(adev, "SSDB", &sensor->ssdb,
@@ -303,6 +306,9 @@ static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg,if (ret) goto err_put_adev; +scnprintf (sensor->name,sizeof (sensor->name),"%s-%u" , + cfg->hid, sensor->ssdb.link); +if (sensor->ssdb.vcmtype >ARRAY_SIZE (cio2_vcm_types)) {dev_warn (&adev->dev,"Unknown VCM type %d\n" , sensor->ssdb.vcmtype);
drivers/media/pci/intel/ipu3/cio2-bridge.h +1 -1
@@ -113,7 +113,7 @@ struct cio2_sensor_config { };struct cio2_sensor { -char name[ACPI_ID_LEN ]; +char name[ACPI_ID_LEN +4 ];struct acpi_device *adev;struct i2c_client *vcm_i2c_client;
Signature · 1 line
2.39.1
Quoted 24 lines · On Fri, Mar 03, 2023 at 10:44:32PM +0800, [email protected] wrote:
From: Bingbu Cao <[email protected]>
In current cio2-bridge, it is using the hid as node name to register software node and swnode will create kobject and sysfs entry with the node name, if there are multiple sensors and VCMs which are sharing same HID name, it will cause the software nodes registration failure:
[ 7.142311] sysfs: cannot create duplicate filename '/kernel/software_nodes/dw9714' ... [ 7.142328] Call Trace: [ 7.142330] <TASK> [ 7.142336] dump_stack_lvl+0x49/0x63 [ 7.142341] dump_stack+0x10/0x16 [ 7.142343] sysfs_warn_dup.cold+0x17/0x2b [ 7.142346] sysfs_create_dir_ns+0xbc/0xd0 [ 7.142351] kobject_add_internal+0xb1/0x2b0 [ 7.142356] kobject_init_and_add+0x71/0xa0 [ 7.142360] swnode_register+0x136/0x210 [ 7.142363] software_node_register+0xd2/0x120 [ 7.142364] software_node_register_nodes+0x83/0xf0 [ 7.142366] ? acpi_get_physical_device_location+0x65/0xc0 [ 7.142371] cio2_bridge_init+0x82a/0xb5e ... [ 7.142448] kobject_add_internal failed for dw9714 with -EEXIST,
Quoted 1 line
don't try to register things with the same name in the same directory.
Please cut unneeded context of the backtrace as it's explained in the Submitting Patches documentation.
Quoted 2 lines
One solution is appending the sensor link(Mipi Port) in SSDB as suffix of the node name to fix this problem.
...
drivers/media/pci/intel/ipu3/cio2-bridge.c static void cio2_bridge_create_connection_swnodes(struct cio2_bridge *bridge, · line 236
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c +4
-0+if (sensor->ssdb.vcmtype) { +scnprintf (vcm_name,sizeof (vcm_name),"%s-%u" , + cio2_vcm_types[sensor->ssdb.vcmtype -1 ], + sensor->ssdb.link);
Is using 'c' variant a cargo cult? Otherwise explain, why dropping the last part of the number is not a problem.
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c +2
-0+ nodes[SWNODE_VCM ] =NODE_VCM (vcm_name); + }
...
drivers/media/pci/intel/ipu3/cio2-bridge.c static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg, · line 310
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c +2
-0+scnprintf (sensor->name,sizeof (sensor->name),"%s-%u" , + cfg->hid, sensor->ssdb.link);
Ditto.
...
drivers/media/pci/intel/ipu3/cio2-bridge.h struct cio2_sensor_config { · line 116
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h +1
-1-char name[ACPI_ID_LEN ]; +char name[ACPI_ID_LEN +4 ];
Why 4 is chosen? This needs an explanation.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Any,
Thanks for your review.
------------------------------------------------------------------------
BRs,
Intel VTG - Linux & Chrome IPU SW
Bingbu Cao
Quoted 36 lines
-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Monday, March 6, 2023 19:27
To: Cao, Bingbu <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] media: ipu3-cio2: support multiple sensors and VCMs with HID nameQuoted 8 lines · On Fri, Mar 03, 2023 at 10:44:32PM +0800, [email protected] wrote:
From: Bingbu Cao <[email protected]>
In current cio2-bridge, it is using the hid as node name to register software node and swnode will create kobject and sysfs entry with the node name, if there are multiple sensors and VCMs which are sharing same HID name, it will cause the software nodes registration failure:
[ 7.142311] sysfs: cannot create duplicate filename'/kernel/software_nodes/dw9714'
Quoted 15 lines
...
[ 7.142328] Call Trace: [ 7.142330] <TASK> [ 7.142336] dump_stack_lvl+0x49/0x63 [ 7.142341] dump_stack+0x10/0x16 [ 7.142343] sysfs_warn_dup.cold+0x17/0x2b [ 7.142346] sysfs_create_dir_ns+0xbc/0xd0 [ 7.142351] kobject_add_internal+0xb1/0x2b0 [ 7.142356] kobject_init_and_add+0x71/0xa0 [ 7.142360] swnode_register+0x136/0x210 [ 7.142363] software_node_register+0xd2/0x120 [ 7.142364] software_node_register_nodes+0x83/0xf0 [ 7.142366] ? acpi_get_physical_device_location+0x65/0xc0 [ 7.142371] cio2_bridge_init+0x82a/0xb5e ... [ 7.142448] kobject_add_internal failed for dw9714 with -EEXIST, don'tQuoted 1 line
try to register things with the same name in the same directory.
Quoted 2 lines
Please cut unneeded context of the backtrace as it's explained in the Submitting Patches documentation.
Thanks, will amend in v2.
Quoted 6 lines
Quoted 3 lines
One solution is appending the sensor link(Mipi Port) in SSDB as suffix of the node name to fix this problem.
...
Quoted 7 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c static void cio2_bridge_create_connection_swnodes(struct cio2_bridge *bridge, · line 236
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c +4
-0+if (sensor->ssdb.vcmtype) { +scnprintf (vcm_name,sizeof (vcm_name),"%s-%u" , + cio2_vcm_types[sensor->ssdb.vcmtype -1 ], + sensor->ssdb.link);Is using 'c' variant a cargo cult? Otherwise explain, why dropping the last part of the number is not a problem.
Sorry, I can't understand. What is cargo cult?
Quoted 12 lines
Quoted 3 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c +2
-0+ nodes[SWNODE_VCM ] =NODE_VCM (vcm_name); + }...
drivers/media/pci/intel/ipu3/cio2-bridge.c static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg, · line 310
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c +2
-0+scnprintf (sensor->name,sizeof (sensor->name),"%s-%u" , + cfg->hid, sensor->ssdb.link);Ditto.
Quoted 6 lines
...
drivers/media/pci/intel/ipu3/cio2-bridge.h struct cio2_sensor_config { · line 116
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h +1
-1-char name[ACPI_ID_LEN ]; +char name[ACPI_ID_LEN +4 ];Why 4 is chosen? This needs an explanation.
'link' is u8, so it is supposed to be max 4 characters along with '-'.
Quoted 5 lines
--
With Best Regards,
Andy Shevchenko
Quoted 3 lines · Bingbu
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Monday, March 6, 2023 19:27
On Fri, Mar 03, 2023 at 10:44:32PM +0800, [email protected] wrote:
...
Quoted 9 lines
Quoted 7 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c static void cio2_bridge_create_connection_swnodes(struct cio2_bridge *bridge, · line 236
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c +4
-0+if (sensor->ssdb.vcmtype) { +scnprintf (vcm_name,sizeof (vcm_name),"%s-%u" , + cio2_vcm_types[sensor->ssdb.vcmtype -1 ], + sensor->ssdb.link);Is using 'c' variant a cargo cult? Otherwise explain, why dropping the last part of the number is not a problem.
Sorry, I can't understand. What is cargo cult?
Use of sCnprintf(). I.o.w. can you explain the point of using it instead of simply snprintf()?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c +2
-0+ nodes[SWNODE_VCM ] =NODE_VCM (vcm_name); + }
...
Quoted 2 lines
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg, · line 310
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c +2
-0+scnprintf (sensor->name,sizeof (sensor->name),"%s-%u" , + cfg->hid, sensor->ssdb.link);
Ditto.
...
Quoted 6 lines
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h struct cio2_sensor_config { · line 116
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h +1
-1-char name[ACPI_ID_LEN ]; +char name[ACPI_ID_LEN +4 ];Why 4 is chosen? This needs an explanation.
'link' is u8, so it is supposed to be max 4 characters along with '-'.
It should be mentioned somewhere.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy,
Quoted 15 lines · Andy Shevchenko
Quoted 3 lines · Bingbu
Quoted 3 lines
From: Andy Shevchenko <[email protected]>
Sent: Monday, March 6, 2023 19:27
On Fri, Mar 03, 2023 at 10:44:32PM +0800, [email protected] wrote:...
Quoted 8 lines
Quoted 7 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c static void cio2_bridge_create_connection_swnodes(struct cio2_bridge *bridge, · line 236
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c +4
-0+if (sensor->ssdb.vcmtype) { +scnprintf (vcm_name,sizeof (vcm_name),"%s-%u" , + cio2_vcm_types[sensor->ssdb.vcmtype -1 ], + sensor->ssdb.link);Is using 'c' variant a cargo cult? Otherwise explain, why dropping the last part of the number is not a problem.
Quoted 4 lines
Quoted 1 line
Sorry, I can't understand. What is cargo cult?
Use of
sCnprintf(). I.o.w. can you explain the point of using it instead of simplysnprintf()?
Thanks, I see and will use simply snprintf() instead in v2.
Quoted 13 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c +2
-0+ nodes[SWNODE_VCM ] =NODE_VCM (vcm_name); + }...
Quoted 2 lines
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c static int cio2_bridge_connect_sensor(const struct cio2_sensor_config *cfg, · line 310
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.c +2
-0+scnprintf (sensor->name,sizeof (sensor->name),"%s-%u" , + cfg->hid, sensor->ssdb.link);Ditto.
...
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h struct cio2_sensor_config { · line 116
Quoted 2 lines
drivers/media/pci/intel/ipu3/cio2-bridge.h +1
-1-char name[ACPI_ID_LEN ]; +char name[ACPI_ID_LEN +4 ];Why 4 is chosen? This needs an explanation.
'link' is u8, so it is supposed to be max 4 characters along with '-'.
It should be mentioned somewhere.
Will add a comment.
Quoted 1 line
Signature · 2 lines
Best regards, Bingbu Cao