Skip to contentSkip to conversation

HID: amd_sfh: Return immediately if no sensor is found

PATCH In review Basavaraj Natikar 5 participants 8 messages Oct 3, 2024 – Oct 9, 2024

Subsystems (3)
lore
Share & tools
lore

Basavaraj Natikar

author maintainer
#0 lore raw

PATCH 1/1 HID: amd_sfh: Return immediately if no sensor is found

There is no need for additional cleanup, as all resources are managed. Additionally, if no sensor is found, there will be no initialization of HID devices. Therefore, return immediately if no sensor is detected.

Fixes 8031b001da70 ("HID: amd_sfh: Move sensor discovery before HID device initialization")
---
 drivers/hid/amd-sfh-hid/amd_sfh_client.c | 3 +--
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c   | 4 +++-
 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/hid/amd-sfh-hid/amd_sfh_client.c +1 -2
index 4b59687ff5d8..3fcb971d5fda 100644
@@ -297,8 +297,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
 	    (mp2_ops->discovery_status && mp2_ops->discovery_status(privdata) == 0)) {
 		dev_warn(dev, "Failed to discover, sensors not enabled is %d\n",
 			 cl_data->is_any_sensor_enabled);
-		rc = -EOPNOTSUPP;
-		goto cleanup;
+		return -EOPNOTSUPP;
 	}
 
 	for (i = 0; i < cl_data->num_hid_devices; i++) {
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +3 -1
index 0c28ca349bcd..1300f122b524 100644
@@ -351,7 +351,9 @@ static void sfh_init_work(struct work_struct *work)
 
 	rc = amd_sfh_hid_client_init(mp2);
 	if (rc) {
-		amd_sfh_clear_intr(mp2);
+		if (rc != -EOPNOTSUPP)
+			amd_sfh_clear_intr(mp2);
+
 		dev_err(&pdev->dev, "amd_sfh_hid_client_init failed err %d\n", rc);
 		return;
 	}
Signature · 1 line
2.25.1
#1 lore raw

[CCing the three reporters and the regressions list]

Quoted 3 lines · Basavaraj Natikar

There is no need for additional cleanup, as all resources are managed. Additionally, if no sensor is found, there will be no initialization of HID devices. Therefore, return immediately if no sensor is detected.

I'm not a reviewer, so feel free to ignore the follow comment:

I think the patch description should mentioned that this bug caused Memory Errors / Page Faults / btrfs going read-only / btrfs disk corruption, as that is a crucial detail for later and downstreams that need to consider when deciding about backporting.

Quoted 2 lines
Fixes 8031b001da70 ("HID: amd_sfh: Move sensor discovery before HID device initialization")

Some reported-by tags IMHO would be appropriate to give credit; all three reporters already agreed to use their email address in public.

There meanwhile is also one comment in the bugzilla ticket that could be read as a tested-by tag.

Maybe a Link: to
https://lore.kernel.org/all/[email protected]/
might be appropriate as well.

Ohh, and participation in stable is optional, but given the severeness on the problem: would you maybe be willing to add a stable tag to the commit to ensure this is backported to affected stable series quickly?

Ciao, Thorsten

Quoted 35 lines
---
 drivers/hid/amd-sfh-hid/amd_sfh_client.c | 3 +--
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c   | 4 +++-
 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/hid/amd-sfh-hid/amd_sfh_client.c +1 -2
index 4b59687ff5d8..3fcb971d5fda 100644
@@ -297,8 +297,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
 	    (mp2_ops->discovery_status && mp2_ops->discovery_status(privdata) == 0)) {
 		dev_warn(dev, "Failed to discover, sensors not enabled is %d\n",
 			 cl_data->is_any_sensor_enabled);
-		rc = -EOPNOTSUPP;
-		goto cleanup;
+		return -EOPNOTSUPP;
 	}
 
 	for (i = 0; i < cl_data->num_hid_devices; i++) {
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +3 -1
index 0c28ca349bcd..1300f122b524 100644
@@ -351,7 +351,9 @@ static void sfh_init_work(struct work_struct *work)
 
 	rc = amd_sfh_hid_client_init(mp2);
 	if (rc) {
-		amd_sfh_clear_intr(mp2);
+		if (rc != -EOPNOTSUPP)
+			amd_sfh_clear_intr(mp2);
+
 		dev_err(&pdev->dev, "amd_sfh_hid_client_init failed err %d\n", rc);
 		return;
 	}
#2 lore raw
Quoted 23 lines · Linux regression tracking (Thorsten Leemhuis)

[CCing the three reporters and the regressions list]

Quoted 3 lines · Basavaraj Natikar

There is no need for additional cleanup, as all resources are managed. Additionally, if no sensor is found, there will be no initialization of HID devices. Therefore, return immediately if no sensor is detected.

I'm not a reviewer, so feel free to ignore the follow comment:

I think the patch description should mentioned that this bug caused Memory Errors / Page Faults / btrfs going read-only / btrfs disk corruption, as that is a crucial detail for later and downstreams that need to consider when deciding about backporting.

Quoted 2 lines
Fixes 8031b001da70 ("HID: amd_sfh: Move sensor discovery before HID device initialization")

Some reported-by tags IMHO would be appropriate to give credit; all three reporters already agreed to use their email address in public.

There meanwhile is also one comment in the bugzilla ticket that could be read as a tested-by tag.

Quoted 7 lines

Maybe a Link: to
https://lore.kernel.org/all/[email protected]/
might be appropriate as well.

Ohh, and participation in stable is optional, but given the severeness on the problem: would you maybe be willing to add a stable tag to the commit to ensure this is backported to affected stable series quickly?

Fully agree here. It would definitely help if the submitter of the patch keeps track of all of these instead of relying on the maintainers or Thorsten to do the tedious work.

I was about to apply the patch, but I still have one remark on the fix itself.

Quoted 9 lines

Ciao, Thorsten

Quoted 6 lines
---
 drivers/hid/amd-sfh-hid/amd_sfh_client.c | 3 +--
 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c   | 4 +++-
 2 files changed, 4 insertions(+), 3 deletions(-)
Quoted 11 lines

drivers/hid/amd-sfh-hid/amd_sfh_client.c int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) · line 300

Quoted 11 lines
drivers/hid/amd-sfh-hid/amd_sfh_client.c +1 -2
index 4b59687ff5d8..3fcb971d5fda 100644
@@ -297,8 +297,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
 	    (mp2_ops->discovery_status && mp2_ops->discovery_status(privdata) == 0)) {
 		dev_warn(dev, "Failed to discover, sensors not enabled is %d\n",
 			 cl_data->is_any_sensor_enabled);
-		rc = -EOPNOTSUPP;
-		goto cleanup;
+		return -EOPNOTSUPP;

so cleanup is doing:
cleanup:

	amd_sfh_hid_client_deinit(privdata);
	for (i = 0; i < cl_data->num_hid_devices; i++) {
		devm_kfree(dev, cl_data->feature_report[i]);
		devm_kfree(dev, in_data->input_report[i]);
		devm_kfree(dev, cl_data->report_descr[i]);
	}
	return rc;

Would that means that the memory corruption appears during amd_sfh_hid_client_deinit(), or...

Quoted 9 lines
Quoted 9 lines
drivers/hid/amd-sfh-hid/amd_sfh_client.c +0 -0
 	}
 
 	for (i = 0; i < cl_data->num_hid_devices; i++) {
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +0 -0
index 0c28ca349bcd..1300f122b524 100644
@@ -351,7 +351,9 @@ static void sfh_init_work(struct work_struct *work)
 
Quoted 5 lines

drivers/hid/amd-sfh-hid/amd_sfh_pcie.c static void sfh_init_work(struct work_struct *work) · line 355

Quoted 5 lines
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +2 -1
 	rc = amd_sfh_hid_client_init(mp2);
 	if (rc) {
-		amd_sfh_clear_intr(mp2);
+		if (rc != -EOPNOTSUPP)
+			amd_sfh_clear_intr(mp2);

... or during amd_sfh_clear_intr()?

This very much looks like a band-aid (I know it is because you can not reproduce, not blaming anyone), but I'd like to know a little bit more if the bug is not appearing anywhere else in the normal processing of the driver itself.

Also a comment explaining why this is the only case where amd_sfh_clear_intr() should not be called would be appreciated.

So all in all, I have a feeling one of these 2 functions is not making a proper check and I would rather fix the root cause, not the symptoms.

Cheers,
Benjamin

PS: sorry, I know this is a long standing issue, but I'd rather not paper over a bigger issue :/

Quoted 5 lines
Quoted 4 lines
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +1 -0
+
 		dev_err(&pdev->dev, "amd_sfh_hid_client_init failed err %d\n", rc);
 		return;
 	}
#3 lore raw
Quoted 90 lines · Benjamin Tissoires
Quoted 21 lines · Linux regression tracking (Thorsten Leemhuis)

[CCing the three reporters and the regressions list]

Quoted 3 lines · Basavaraj Natikar

There is no need for additional cleanup, as all resources are managed. Additionally, if no sensor is found, there will be no initialization of HID devices. Therefore, return immediately if no sensor is detected.

I'm not a reviewer, so feel free to ignore the follow comment:

I think the patch description should mentioned that this bug caused Memory Errors / Page Faults / btrfs going read-only / btrfs disk corruption, as that is a crucial detail for later and downstreams that need to consider when deciding about backporting.

Quoted 2 lines
Fixes 8031b001da70 ("HID: amd_sfh: Move sensor discovery before HID device initialization")

Some reported-by tags IMHO would be appropriate to give credit; all three reporters already agreed to use their email address in public.

There meanwhile is also one comment in the bugzilla ticket that could be read as a tested-by tag.

Quoted 7 lines

Maybe a Link: to
https://lore.kernel.org/all/[email protected]/
might be appropriate as well.

Ohh, and participation in stable is optional, but given the severeness on the problem: would you maybe be willing to add a stable tag to the commit to ensure this is backported to affected stable series quickly?

Fully agree here. It would definitely help if the submitter of the patch keeps track of all of these instead of relying on the maintainers or Thorsten to do the tedious work.

I was about to apply the patch, but I still have one remark on the fix itself.

Quoted 8 lines

Ciao, Thorsten

Quoted 6 lines
---
  drivers/hid/amd-sfh-hid/amd_sfh_client.c | 3 +--
  drivers/hid/amd-sfh-hid/amd_sfh_pcie.c   | 4 +++-
  2 files changed, 4 insertions(+), 3 deletions(-)
Quoted 11 lines

drivers/hid/amd-sfh-hid/amd_sfh_client.c int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) · line 300

Quoted 11 lines
drivers/hid/amd-sfh-hid/amd_sfh_client.c +1 -2
index 4b59687ff5d8..3fcb971d5fda 100644
@@ -297,8 +297,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
  	    (mp2_ops->discovery_status && mp2_ops->discovery_status(privdata) == 0)) {
  		dev_warn(dev, "Failed to discover, sensors not enabled is %d\n",
  			 cl_data->is_any_sensor_enabled);
-		rc = -EOPNOTSUPP;
-		goto cleanup;
+		return -EOPNOTSUPP;

so cleanup is doing:
cleanup:

	amd_sfh_hid_client_deinit(privdata);
	for (i = 0; i < cl_data->num_hid_devices; i++) {
		devm_kfree(dev, cl_data->feature_report[i]);
		devm_kfree(dev, in_data->input_report[i]);
		devm_kfree(dev, cl_data->report_descr[i]);
	}
	return rc;

Would that means that the memory corruption appears during amd_sfh_hid_client_deinit(), or...

Quoted 9 lines
Quoted 9 lines
drivers/hid/amd-sfh-hid/amd_sfh_client.c +0 -0
  	}
 
  	for (i = 0; i < cl_data->num_hid_devices; i++) {
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +0 -0
index 0c28ca349bcd..1300f122b524 100644
@@ -351,7 +351,9 @@ static void sfh_init_work(struct work_struct *work)
 
Quoted 5 lines

drivers/hid/amd-sfh-hid/amd_sfh_pcie.c static void sfh_init_work(struct work_struct *work) · line 355

Quoted 5 lines
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +2 -1
  	rc = amd_sfh_hid_client_init(mp2);
  	if (rc) {
-		amd_sfh_clear_intr(mp2);
+		if (rc != -EOPNOTSUPP)
+			amd_sfh_clear_intr(mp2);

... or during amd_sfh_clear_intr()?

This very much looks like a band-aid (I know it is because you can not reproduce, not blaming anyone), but I'd like to know a little bit more if the bug is not appearing anywhere else in the normal processing of the driver itself.

Quoted 5 lines

Also a comment explaining why this is the only case where amd_sfh_clear_intr() should not be called would be appreciated.

So all in all, I have a feeling one of these 2 functions is not making a proper check and I would rather fix the root cause, not the symptoms.

Sure Benjamin, I have added the latest cleanup patch in the bug ID to see if that helps resolve the issue and to find the root cause analysis.

Thanks
--
Basavaraj

#4 lore raw
In reply to Benjamin Tissoires
Quoted 40 lines · Benjamin Tissoires

On Oct 04 2024, Linux regression tracking (Thorsten Leemhuis) wrote:

so cleanup is doing:
cleanup:

	amd_sfh_hid_client_deinit(privdata);
	for (i = 0; i < cl_data->num_hid_devices; i++) {
		devm_kfree(dev, cl_data->feature_report[i]);
		devm_kfree(dev, in_data->input_report[i]);
		devm_kfree(dev, cl_data->report_descr[i]);
	}
	return rc;

Would that means that the memory corruption appears during amd_sfh_hid_client_deinit(), or...

Quoted 9 lines
Quoted 9 lines
drivers/hid/amd-sfh-hid/amd_sfh_client.c +0 -0
 	}
 
 	for (i = 0; i < cl_data->num_hid_devices; i++) {
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +0 -0
index 0c28ca349bcd..1300f122b524 100644
@@ -351,7 +351,9 @@ static void sfh_init_work(struct work_struct *work)
 
Quoted 5 lines

drivers/hid/amd-sfh-hid/amd_sfh_pcie.c static void sfh_init_work(struct work_struct *work) · line 355

Quoted 5 lines
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +2 -1
 	rc = amd_sfh_hid_client_init(mp2);
 	if (rc) {
-		amd_sfh_clear_intr(mp2);
+		if (rc != -EOPNOTSUPP)
+			amd_sfh_clear_intr(mp2);

... or during amd_sfh_clear_intr()?

This very much looks like a band-aid (I know it is because you can not reproduce, not blaming anyone), but I'd like to know a little bit more if the bug is not appearing anywhere else in the normal processing of the driver itself.

Also a comment explaining why this is the only case where amd_sfh_clear_intr() should not be called would be appreciated.

Quoted 8 lines

So all in all, I have a feeling one of these 2 functions is not making a proper check and I would rather fix the root cause, not the symptoms.

Cheers,
Benjamin

PS: sorry, I know this is a long standing issue, but I'd rather not paper over a bigger issue :/

Yeah, me to!

There was a new patch in bugzilla and people tested it (see
https://bugzilla.kernel.org/show_bug.cgi?id=219331 for details) , but nothing has happened now for 48 hours, so please allow me to ask:

Basavaraj Natikar, is there any hope that a proper fix will emerge soon?

Sorry, normally I would wait a lot longer before asking things like this, but given the severeness of the problem I thought a inquiry for a quick status update was in order.

Ciao, Thorsten

#5 lore raw
Quoted 48 lines · Linux regression tracking (Thorsten Leemhuis)
Quoted 39 lines · Benjamin Tissoires

On Oct 04 2024, Linux regression tracking (Thorsten Leemhuis) wrote:

so cleanup is doing:
cleanup:

	amd_sfh_hid_client_deinit(privdata);
	for (i = 0; i < cl_data->num_hid_devices; i++) {
		devm_kfree(dev, cl_data->feature_report[i]);
		devm_kfree(dev, in_data->input_report[i]);
		devm_kfree(dev, cl_data->report_descr[i]);
	}
	return rc;

Would that means that the memory corruption appears during amd_sfh_hid_client_deinit(), or...

Quoted 9 lines
Quoted 9 lines
  	}
  
  	for (i = 0; i < cl_data->num_hid_devices; i++) {
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +0 -0
index 0c28ca349bcd..1300f122b524 100644
@@ -351,7 +351,9 @@ static void sfh_init_work(struct work_struct *work)
 
Quoted 5 lines

drivers/hid/amd-sfh-hid/amd_sfh_pcie.c static void sfh_init_work(struct work_struct *work) · line 355

Quoted 5 lines
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +2 -1
  	rc = amd_sfh_hid_client_init(mp2);
  	if (rc) {
-		amd_sfh_clear_intr(mp2);
+		if (rc != -EOPNOTSUPP)
+			amd_sfh_clear_intr(mp2);

... or during amd_sfh_clear_intr()?

This very much looks like a band-aid (I know it is because you can not reproduce, not blaming anyone), but I'd like to know a little bit more if the bug is not appearing anywhere else in the normal processing of the driver itself.

Also a comment explaining why this is the only case where amd_sfh_clear_intr() should not be called would be appreciated.

Quoted 8 lines

So all in all, I have a feeling one of these 2 functions is not making a proper check and I would rather fix the root cause, not the symptoms.

Cheers,
Benjamin

PS: sorry, I know this is a long standing issue, but I'd rather not paper over a bigger issue :/

Quoted 7 lines

Yeah, me to!

There was a new patch in bugzilla and people tested it (see
https://bugzilla.kernel.org/show_bug.cgi?id=219331 for details) , but nothing has happened now for 48 hours, so please allow me to ask:

Basavaraj Natikar, is there any hope that a proper fix will emerge soon?

Yes , please find link for the fix as mentioned in bugid.

https://lore.kernel.org/all/[email protected]/

Thanks,
--
Basavaraj

#6 lore raw
Quoted 13 lines · Basavaraj Natikar
Quoted 12 lines · Linux regression tracking (Thorsten Leemhuis)
Quoted 4 lines · Benjamin Tissoires

On Oct 04 2024, Linux regression tracking (Thorsten Leemhuis) wrote:

PS: sorry, I know this is a long standing issue, but I'd rather not paper over a bigger issue :/

Yeah, me to!

There was a new patch in bugzilla and people tested it (see
https://bugzilla.kernel.org/show_bug.cgi?id=219331 for details) , but nothing has happened now for 48 hours, so please allow me to ask:

Quoted 6 lines
Quoted 1 line

Basavaraj Natikar, is there any hope that a proper fix will emerge soon?

Yes , please find link for the fix as mentioned in bugid.

https://lore.kernel.org/all/20241009144757.3577625-1-
[email protected]/

Great, many thx!

Nitpicking: still no stable tag though. :-/ And ideally Richard and Skyler would get a "Reported-by" as well.

Ciao, Thorsten

maintainer
#7 lore raw
Quoted 13 lines · Linux regression tracking (Thorsten Leemhuis)
Quoted 13 lines
Quoted 10 lines
Quoted 2 lines

PS: sorry, I know this is a long standing issue, but I'd rather not paper over a bigger issue :/

Yeah, me to!

There was a new patch in bugzilla and people tested it (see
https://bugzilla.kernel.org/show_bug.cgi?id=219331 for details) , but nothing has happened now for 48 hours, so please allow me to ask:

Basavaraj Natikar, is there any hope that a proper fix will emerge soon?

Yes , please find link for the fix as mentioned in bugid.

Quoted 7 lines
Quoted 2 lines

https://lore.kernel.org/all/20241009144757.3577625-1-
[email protected]/

Great, many thx!

Nitpicking: still no stable tag though. :-/ And ideally Richard and Skyler would get a "Reported-by" as well.

I don't care all that much about stable tag, but if there are more Reported-by:s, I like to give credit where it's due, and I don't think rebasing for-6.12/upstream-fixes because of that would break anybody.

So please feel free to send additional tags, and I'll rewrite it.

Signature · 2 lines
Jiri Kosina
SUSE Labs