Commit 0c4915b6 authored by Barnabás Pőcze's avatar Barnabás Pőcze Committed by Hans de Goede
Browse files

platform/x86: ideapad-laptop: use for_each_set_bit() helper to simplify event processing



The current code used the combination of a for loop + test_bit,
which can be simplified using for_each_set_bit(), so utilize that.

Signed-off-by: default avatarBarnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20210203215403.290792-10-pobrn@protonmail.com


Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
parent 708086b2
Loading
Loading
Loading
Loading
+53 −55
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@

#include <linux/acpi.h>
#include <linux/backlight.h>
#include <linux/bitops.h>
#include <linux/debugfs.h>
#include <linux/device.h>
#include <linux/dmi.h>
@@ -1018,8 +1019,7 @@ static void ideapad_check_special_buttons(struct ideapad_private *priv)

	read_ec_data(priv->adev->handle, VPCCMD_R_SPECIAL_BUTTONS, &value);

	for (bit = 0; bit < 16; bit++) {
		if (test_bit(bit, &value)) {
	for_each_set_bit (bit, &value, 16) {
		switch (bit) {
		case 0:	/* Z580 */
		case 6:	/* Z570 */
@@ -1036,7 +1036,6 @@ static void ideapad_check_special_buttons(struct ideapad_private *priv)
		}
	}
}
}

/*
 * backlight
@@ -1161,7 +1160,7 @@ static void ideapad_sync_touchpad_state(struct ideapad_private *priv)
static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
{
	struct ideapad_private *priv = data;
	unsigned long vpc1, vpc2, vpc_bit;
	unsigned long vpc1, vpc2, bit;

	if (read_ec_data(handle, VPCCMD_R_VPC1, &vpc1))
		return;
@@ -1169,9 +1168,9 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
		return;

	vpc1 = (vpc2 << 8) | vpc1;
	for (vpc_bit = 0; vpc_bit < 16; vpc_bit++) {
		if (test_bit(vpc_bit, &vpc1)) {
			switch (vpc_bit) {

	for_each_set_bit (bit, &vpc1, 16) {
		switch (bit) {
		case 9:
			ideapad_sync_rfk_state(priv);
			break;
@@ -1180,7 +1179,7 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
		case 8:
		case 7:
		case 6:
				ideapad_input_report(priv, vpc_bit);
			ideapad_input_report(priv, bit);
			break;
		case 5:
			ideapad_sync_touchpad_state(priv);
@@ -1205,8 +1204,7 @@ static void ideapad_acpi_notify(acpi_handle handle, u32 event, void *data)
			 */
			break;
		default:
				pr_info("Unknown event: %lu\n", vpc_bit);
			}
			pr_info("Unknown event: %lu\n", bit);
		}
	}
}