Skip to content

Commit 7450f1b

Browse files
JoseExpositogregkh
authored andcommitted
HID: input: rename hidinput_set_battery_charge_status()
[ Upstream commit a82231b ] In preparation for a patch fixing a bug affecting hidinput_set_battery_charge_status(), rename the function to hidinput_update_battery_charge_status() and move it up so it can be used by hidinput_update_battery(). Refactor, no functional changes. Tested-by: 卢国宏 <luguohong@xiaomi.com> Signed-off-by: José Expósito <jose.exposito89@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.com> Stable-dep-of: e94536e ("HID: input: report battery status changes immediately") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8d49313 commit 7450f1b

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

drivers/hid/hid-input-test.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@
77

88
#include <kunit/test.h>
99

10-
static void hid_test_input_set_battery_charge_status(struct kunit *test)
10+
static void hid_test_input_update_battery_charge_status(struct kunit *test)
1111
{
1212
struct hid_device *dev;
1313
bool handled;
1414

1515
dev = kunit_kzalloc(test, sizeof(*dev), GFP_KERNEL);
1616
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
1717

18-
handled = hidinput_set_battery_charge_status(dev, HID_DG_HEIGHT, 0);
18+
handled = hidinput_update_battery_charge_status(dev, HID_DG_HEIGHT, 0);
1919
KUNIT_EXPECT_FALSE(test, handled);
2020
KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_UNKNOWN);
2121

22-
handled = hidinput_set_battery_charge_status(dev, HID_BAT_CHARGING, 0);
22+
handled = hidinput_update_battery_charge_status(dev, HID_BAT_CHARGING, 0);
2323
KUNIT_EXPECT_TRUE(test, handled);
2424
KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_DISCHARGING);
2525

26-
handled = hidinput_set_battery_charge_status(dev, HID_BAT_CHARGING, 1);
26+
handled = hidinput_update_battery_charge_status(dev, HID_BAT_CHARGING, 1);
2727
KUNIT_EXPECT_TRUE(test, handled);
2828
KUNIT_EXPECT_EQ(test, dev->battery_charge_status, POWER_SUPPLY_STATUS_CHARGING);
2929
}
@@ -63,7 +63,7 @@ static void hid_test_input_get_battery_property(struct kunit *test)
6363
}
6464

6565
static struct kunit_case hid_input_tests[] = {
66-
KUNIT_CASE(hid_test_input_set_battery_charge_status),
66+
KUNIT_CASE(hid_test_input_update_battery_charge_status),
6767
KUNIT_CASE(hid_test_input_get_battery_property),
6868
{ }
6969
};

drivers/hid/hid-input.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,20 @@ static void hidinput_cleanup_battery(struct hid_device *dev)
595595
dev->battery = NULL;
596596
}
597597

598+
static bool hidinput_update_battery_charge_status(struct hid_device *dev,
599+
unsigned int usage, int value)
600+
{
601+
switch (usage) {
602+
case HID_BAT_CHARGING:
603+
dev->battery_charge_status = value ?
604+
POWER_SUPPLY_STATUS_CHARGING :
605+
POWER_SUPPLY_STATUS_DISCHARGING;
606+
return true;
607+
}
608+
609+
return false;
610+
}
611+
598612
static void hidinput_update_battery(struct hid_device *dev, int value)
599613
{
600614
int capacity;
@@ -617,20 +631,6 @@ static void hidinput_update_battery(struct hid_device *dev, int value)
617631
power_supply_changed(dev->battery);
618632
}
619633
}
620-
621-
static bool hidinput_set_battery_charge_status(struct hid_device *dev,
622-
unsigned int usage, int value)
623-
{
624-
switch (usage) {
625-
case HID_BAT_CHARGING:
626-
dev->battery_charge_status = value ?
627-
POWER_SUPPLY_STATUS_CHARGING :
628-
POWER_SUPPLY_STATUS_DISCHARGING;
629-
return true;
630-
}
631-
632-
return false;
633-
}
634634
#else /* !CONFIG_HID_BATTERY_STRENGTH */
635635
static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type,
636636
struct hid_field *field, bool is_percentage)
@@ -642,14 +642,14 @@ static void hidinput_cleanup_battery(struct hid_device *dev)
642642
{
643643
}
644644

645-
static void hidinput_update_battery(struct hid_device *dev, int value)
645+
static bool hidinput_update_battery_charge_status(struct hid_device *dev,
646+
unsigned int usage, int value)
646647
{
648+
return false;
647649
}
648650

649-
static bool hidinput_set_battery_charge_status(struct hid_device *dev,
650-
unsigned int usage, int value)
651+
static void hidinput_update_battery(struct hid_device *dev, int value)
651652
{
652-
return false;
653653
}
654654
#endif /* CONFIG_HID_BATTERY_STRENGTH */
655655

@@ -1515,7 +1515,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
15151515
return;
15161516

15171517
if (usage->type == EV_PWR) {
1518-
bool handled = hidinput_set_battery_charge_status(hid, usage->hid, value);
1518+
bool handled = hidinput_update_battery_charge_status(hid, usage->hid, value);
15191519

15201520
if (!handled)
15211521
hidinput_update_battery(hid, value);

0 commit comments

Comments
 (0)