All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ambrož Bizjak" <abizjak.pro@gmail.com>
To: platform-driver-x86@vger.kernel.org
Subject: ideapad-laptop incorrectly sets RF-kill block on initialization
Date: Wed, 17 Mar 2021 21:39:39 +0100	[thread overview]
Message-ID: <CAJ4FQ9A=Xcom1d0fWVw+dRLX+yKAg3ACeXW=LgQEo9W-D7EfrQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1671 bytes --]

Hi,

I have found an issue in the ideapad-laptop driver which causes WiFi
to not work on the Lenovo Legion Y720 laptop. It seems the issue is
generally present on this laptop as can be found by googling and
finding that the workaround is to blacklist ideapad-laptop.

In the code comment here:
https://github.com/torvalds/linux/blob/1df27313f50a57497c1faeb6a6ae4ca939c85a7d/drivers/platform/x86/ideapad-laptop.c#L1462
it is explained that the driver has a list of devices which are known
to have an RF-kill switch and for other devices it assumes that it
does not have one. Since the list is in fact empty, one would conclude
that the driver should never cause an RF-kill block. However on this
laptop loading the driver has this exact effect.

The reason is what seems to be a bug here:
https://github.com/torvalds/linux/blob/1df27313f50a57497c1faeb6a6ae4ca939c85a7d/drivers/platform/x86/ideapad-laptop.c#L1001
At initialization, ideapad_register_rfkill() sets the initial RF-kill
block state based on reading the state of the possibly nonexisting
RF-kill switch without considering priv->features.hw_rfkill_switch.
This is inconsistent with ideapad_sync_rfk_state() which sets
unblocked if hw_rfkill_switch is false. The result is that
ideapad_register_rfkill() would block but ideapad_sync_rfk_state()
would unblock as soon as it is called. But on my laptop
ideapad_sync_rfk_state() is presumably never called and the blocked
state persists indefinitely. I have verified this by changing
ideapad_register_rfkill() to use the same logic as
ideapad_sync_rfk_state() which has fixed the problem.

I am attaching a patch for master and 5.4, I have only tested the latter.

[-- Attachment #2: ideapad-laptop-rfkill-master.diff --]
[-- Type: text/x-patch, Size: 580 bytes --]

--- a/drivers/platform/x86/ideapad-laptop.c	2021-03-17 21:27:39.098544023 +0100
+++ b/drivers/platform/x86/ideapad-laptop.c	2021-03-17 21:28:59.059343028 +0100
@@ -998,9 +998,13 @@
 	if (!priv->rfk[dev])
 		return -ENOMEM;
 
-	err = read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode - 1, &rf_enabled);
-	if (err)
+	if (!priv->features.hw_rfkill_switch) {
 		rf_enabled = 1;
+	} else {
+		err = read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode - 1, &rf_enabled);
+		if (err)
+			rf_enabled = 1;
+	}
 
 	rfkill_init_sw_state(priv->rfk[dev], !rf_enabled);
 

[-- Attachment #3: ideapad-laptop-rfkill-5.4.patch --]
[-- Type: text/x-patch, Size: 634 bytes --]

diff -urN linux-5.4.104.orig/drivers/platform/x86/ideapad-laptop.c linux-5.4.104/drivers/platform/x86/ideapad-laptop.c
--- linux-5.4.104.orig/drivers/platform/x86/ideapad-laptop.c	2021-03-16 19:02:12.126383099 +0100
+++ linux-5.4.104/drivers/platform/x86/ideapad-laptop.c	2021-03-16 19:07:04.380961129 +0100
@@ -616,7 +616,8 @@
 	if (!priv->rfk[dev])
 		return -ENOMEM;
 
-	if (read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode-1,
+	if (!priv->has_hw_rfkill_switch ||
+            read_ec_data(priv->adev->handle, ideapad_rfk_data[dev].opcode-1,
 			 &sw_blocked)) {
 		rfkill_init_sw_state(priv->rfk[dev], 0);
 	} else {

             reply	other threads:[~2021-03-17 20:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-17 20:39 Ambrož Bizjak [this message]
2021-03-17 21:11 ` ideapad-laptop incorrectly sets RF-kill block on initialization Barnabás Pőcze

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJ4FQ9A=Xcom1d0fWVw+dRLX+yKAg3ACeXW=LgQEo9W-D7EfrQ@mail.gmail.com' \
    --to=abizjak.pro@gmail.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.