Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1597087 > unrolled thread

[PATCH v4 0/4] fujitsu_init() cleanup

Started byMichał Kępień <kernel@kempniu.pl>
First post2017-03-10 12:00 +0100
Last post2017-03-13 17:10 +0100
Articles 6 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v4 0/4] fujitsu_init() cleanup Michał Kępień <kernel@kempniu.pl> - 2017-03-10 12:00 +0100
    [PATCH v4 3/4] platform/x86: fujitsu-laptop: only register backlight device if FUJ02B1 is present Michał Kępień <kernel@kempniu.pl> - 2017-03-10 12:00 +0100
    [PATCH v4 4/4] platform/x86: fujitsu-laptop: cleanup error labels in fujitsu_init() Michał Kępień <kernel@kempniu.pl> - 2017-03-10 12:00 +0100
    [PATCH v4 1/4] platform/x86: fujitsu-laptop: register backlight device in a separate function Michał Kępień <kernel@kempniu.pl> - 2017-03-10 12:00 +0100
    Re: [PATCH v4 0/4] fujitsu_init() cleanup Jonathan Woithe <jwoithe@just42.net> - 2017-03-10 12:10 +0100
      Re: [PATCH v4 0/4] fujitsu_init() cleanup Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-03-13 17:10 +0100

#1597087 — [PATCH v4 0/4] fujitsu_init() cleanup

FromMichał Kępień <kernel@kempniu.pl>
Date2017-03-10 12:00 +0100
Subject[PATCH v4 0/4] fujitsu_init() cleanup
Message-ID<tjqr9-2Qu-37@gated-at.bofh.it>
These patches should make fujitsu_init() a bit more palatable.  No
changes are made to platform device code yet, for clarity these will be
posted in a separate series after this one gets applied.

Changes from v3:

  - Do not use KBUILD_MODNAME as backlight device name as it breaks
    userspace interface ("fujitsu-laptop" vs. "fujitsu_laptop").

Changes from v2:

  - Patch 2/4 from v2 did not work as expected and was thus replaced
    with a rebased version of patch 3/4 from v1.

  - Added a check in patch 3/4 to prevent a NULL dereference when
    ACPI device FUJ02B1 is not present and ACPI device FUJ02E3 is.

Changes from v1:

  - Rebase on top of reworked Alan Jenkins' cleanup patch series.

  - Drop patch 1/4 from v1 as it has already been applied in reworked
    Alan Jenkins' cleanup patch series.

  - Patch 3/4 from v1 has been replaced with a completely different one
    (patch 2/4).  It needs to be tested on a relevant machine as it is
    based purely on a dump of a DSDT table (further details can be found
    in the patch itself).

  - Patch 3/4 in v2 is a rebased version of patch 8/10 from the reworked
    Alan Jenkins' cleanup patch series.  Patch 2/4 from v2 (the one
    mentioned in the previous bullet point) ensures this one can be
    safely applied without causing a NULL dereference under any
    circumstances.

 drivers/platform/x86/fujitsu-laptop.c | 98 ++++++++++++++++++-----------------
 1 file changed, 50 insertions(+), 48 deletions(-)

-- 
2.12.0

[toc] | [next] | [standalone]


#1597089 — [PATCH v4 3/4] platform/x86: fujitsu-laptop: only register backlight device if FUJ02B1 is present

FromMichał Kępień <kernel@kempniu.pl>
Date2017-03-10 12:00 +0100
Subject[PATCH v4 3/4] platform/x86: fujitsu-laptop: only register backlight device if FUJ02B1 is present
Message-ID<tjqr9-2Qu-43@gated-at.bofh.it>
In reply to#1597087
As the backlight device registered by fujitsu-laptop relies on the
FUJ02B1 ACPI device being present, only register the backlight device
once that ACPI device is detected.

Suggested-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
Signed-off-by: Michał Kępień <kernel@kempniu.pl>
---
 drivers/platform/x86/fujitsu-laptop.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index 165971b102e7..dad7b448f2cd 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -781,6 +781,12 @@ static int acpi_fujitsu_bl_add(struct acpi_device *device)
 		fujitsu_bl->max_brightness = FUJITSU_LCD_N_LEVELS;
 	get_lcd_level();
 
+	if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
+		error = fujitsu_backlight_register();
+		if (error)
+			goto err_unregister_input_dev;
+	}
+
 	return 0;
 
 err_unregister_input_dev:
@@ -797,6 +803,7 @@ static int acpi_fujitsu_bl_remove(struct acpi_device *device)
 	struct fujitsu_bl *fujitsu_bl = acpi_driver_data(device);
 	struct input_dev *input = fujitsu_bl->input;
 
+	backlight_device_unregister(fujitsu_bl->bl_device);
 	input_unregister_device(input);
 
 	fujitsu_bl->acpi_handle = NULL;
@@ -956,7 +963,8 @@ static int acpi_fujitsu_laptop_add(struct acpi_device *device)
 	pr_info("BTNI: [0x%x]\n", call_fext_func(FUNC_BUTTONS, 0x0, 0x0, 0x0));
 
 	/* Sync backlight power status */
-	if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
+	if (fujitsu_bl->bl_device &&
+	    acpi_video_get_backlight_type() == acpi_backlight_vendor) {
 		if (call_fext_func(FUNC_BACKLIGHT, 0x2, 0x4, 0x0) == 3)
 			fujitsu_bl->bl_device->props.power = FB_BLANK_POWERDOWN;
 		else
@@ -1256,17 +1264,9 @@ static int __init fujitsu_init(void)
 	if (ret)
 		goto fail_platform_device2;
 
-	/* Register backlight stuff */
-
-	if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
-		ret = fujitsu_backlight_register();
-		if (ret)
-			goto fail_sysfs_group;
-	}
-
 	ret = platform_driver_register(&fujitsu_pf_driver);
 	if (ret)
-		goto fail_backlight;
+		goto fail_sysfs_group;
 
 	/* Register laptop driver */
 
@@ -1288,8 +1288,6 @@ static int __init fujitsu_init(void)
 	kfree(fujitsu_laptop);
 fail_laptop:
 	platform_driver_unregister(&fujitsu_pf_driver);
-fail_backlight:
-	backlight_device_unregister(fujitsu_bl->bl_device);
 fail_sysfs_group:
 	sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
 			   &fujitsu_pf_attribute_group);
@@ -1313,8 +1311,6 @@ static void __exit fujitsu_cleanup(void)
 
 	platform_driver_unregister(&fujitsu_pf_driver);
 
-	backlight_device_unregister(fujitsu_bl->bl_device);
-
 	sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
 			   &fujitsu_pf_attribute_group);
 
-- 
2.12.0

[toc] | [prev] | [next] | [standalone]


#1597096 — [PATCH v4 4/4] platform/x86: fujitsu-laptop: cleanup error labels in fujitsu_init()

FromMichał Kępień <kernel@kempniu.pl>
Date2017-03-10 12:00 +0100
Subject[PATCH v4 4/4] platform/x86: fujitsu-laptop: cleanup error labels in fujitsu_init()
Message-ID<tjqr9-2Qu-55@gated-at.bofh.it>
In reply to#1597087
Error labels currently used in fujitsu_init() are really hard to follow:
some (fail_laptop) indicate which operation has failed, others
(fail_sysfs_group) indicate where unrolling should start and the rest
(fail_platform_driver) is simply confusing.  Change them to follow the
pattern used throughout the rest of the module, i.e. make every label
indicate the first unrolling operation it leads to.

Signed-off-by: Michał Kępień <kernel@kempniu.pl>
---
 drivers/platform/x86/fujitsu-laptop.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index dad7b448f2cd..75d5f758af59 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -1244,60 +1244,60 @@ static int __init fujitsu_init(void)
 
 	ret = acpi_bus_register_driver(&acpi_fujitsu_bl_driver);
 	if (ret)
-		goto fail_acpi;
+		goto err_free_fujitsu_bl;
 
 	/* Register platform stuff */
 
 	fujitsu_bl->pf_device = platform_device_alloc("fujitsu-laptop", -1);
 	if (!fujitsu_bl->pf_device) {
 		ret = -ENOMEM;
-		goto fail_platform_driver;
+		goto err_unregister_acpi;
 	}
 
 	ret = platform_device_add(fujitsu_bl->pf_device);
 	if (ret)
-		goto fail_platform_device1;
+		goto err_put_platform_device;
 
 	ret =
 	    sysfs_create_group(&fujitsu_bl->pf_device->dev.kobj,
 			       &fujitsu_pf_attribute_group);
 	if (ret)
-		goto fail_platform_device2;
+		goto err_del_platform_device;
 
 	ret = platform_driver_register(&fujitsu_pf_driver);
 	if (ret)
-		goto fail_sysfs_group;
+		goto err_remove_sysfs_group;
 
 	/* Register laptop driver */
 
 	fujitsu_laptop = kzalloc(sizeof(struct fujitsu_laptop), GFP_KERNEL);
 	if (!fujitsu_laptop) {
 		ret = -ENOMEM;
-		goto fail_laptop;
+		goto err_unregister_platform_driver;
 	}
 
 	ret = acpi_bus_register_driver(&acpi_fujitsu_laptop_driver);
 	if (ret)
-		goto fail_laptop1;
+		goto err_free_fujitsu_laptop;
 
 	pr_info("driver " FUJITSU_DRIVER_VERSION " successfully loaded\n");
 
 	return 0;
 
-fail_laptop1:
+err_free_fujitsu_laptop:
 	kfree(fujitsu_laptop);
-fail_laptop:
+err_unregister_platform_driver:
 	platform_driver_unregister(&fujitsu_pf_driver);
-fail_sysfs_group:
+err_remove_sysfs_group:
 	sysfs_remove_group(&fujitsu_bl->pf_device->dev.kobj,
 			   &fujitsu_pf_attribute_group);
-fail_platform_device2:
+err_del_platform_device:
 	platform_device_del(fujitsu_bl->pf_device);
-fail_platform_device1:
+err_put_platform_device:
 	platform_device_put(fujitsu_bl->pf_device);
-fail_platform_driver:
+err_unregister_acpi:
 	acpi_bus_unregister_driver(&acpi_fujitsu_bl_driver);
-fail_acpi:
+err_free_fujitsu_bl:
 	kfree(fujitsu_bl);
 
 	return ret;
-- 
2.12.0

[toc] | [prev] | [next] | [standalone]


#1597098 — [PATCH v4 1/4] platform/x86: fujitsu-laptop: register backlight device in a separate function

FromMichał Kępień <kernel@kempniu.pl>
Date2017-03-10 12:00 +0100
Subject[PATCH v4 1/4] platform/x86: fujitsu-laptop: register backlight device in a separate function
Message-ID<tjqra-2Qu-63@gated-at.bofh.it>
In reply to#1597087
Move code responsible for backlight device registration to a separate
function in order to simplify error handling and decrease indentation.
Simplify initialization of struct backlight_properties.

Signed-off-by: Michał Kępień <kernel@kempniu.pl>
---
 drivers/platform/x86/fujitsu-laptop.c | 38 ++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index e12cc3504d48..5ec596c5053d 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -685,6 +685,25 @@ static const struct dmi_system_id fujitsu_dmi_table[] __initconst = {
 
 /* ACPI device for LCD brightness control */
 
+static int fujitsu_backlight_register(void)
+{
+	struct backlight_properties props = {
+		.brightness = fujitsu_bl->brightness_level,
+		.max_brightness = fujitsu_bl->max_brightness - 1,
+		.type = BACKLIGHT_PLATFORM
+	};
+	struct backlight_device *bd;
+
+	bd = backlight_device_register("fujitsu-laptop", NULL, NULL,
+				       &fujitsu_bl_ops, &props);
+	if (IS_ERR(bd))
+		return PTR_ERR(bd);
+
+	fujitsu_bl->bl_device = bd;
+
+	return 0;
+}
+
 static int acpi_fujitsu_bl_add(struct acpi_device *device)
 {
 	int state = 0;
@@ -1192,7 +1211,7 @@ MODULE_DEVICE_TABLE(acpi, fujitsu_ids);
 
 static int __init fujitsu_init(void)
 {
-	int ret, max_brightness;
+	int ret;
 
 	if (acpi_disabled)
 		return -ENODEV;
@@ -1232,22 +1251,9 @@ static int __init fujitsu_init(void)
 	/* Register backlight stuff */
 
 	if (acpi_video_get_backlight_type() == acpi_backlight_vendor) {
-		struct backlight_properties props;
-
-		memset(&props, 0, sizeof(struct backlight_properties));
-		max_brightness = fujitsu_bl->max_brightness;
-		props.type = BACKLIGHT_PLATFORM;
-		props.max_brightness = max_brightness - 1;
-		fujitsu_bl->bl_device = backlight_device_register("fujitsu-laptop",
-								  NULL, NULL,
-								  &fujitsu_bl_ops,
-								  &props);
-		if (IS_ERR(fujitsu_bl->bl_device)) {
-			ret = PTR_ERR(fujitsu_bl->bl_device);
-			fujitsu_bl->bl_device = NULL;
+		ret = fujitsu_backlight_register();
+		if (ret)
 			goto fail_sysfs_group;
-		}
-		fujitsu_bl->bl_device->props.brightness = fujitsu_bl->brightness_level;
 	}
 
 	ret = platform_driver_register(&fujitsu_pf_driver);
-- 
2.12.0

[toc] | [prev] | [next] | [standalone]


#1597110

FromJonathan Woithe <jwoithe@just42.net>
Date2017-03-10 12:10 +0100
Message-ID<tjqAN-38Z-13@gated-at.bofh.it>
In reply to#1597087
On Fri, Mar 10, 2017 at 11:50:32AM +0100, Micha?? K??pie?? wrote:
> These patches should make fujitsu_init() a bit more palatable.  No
> changes are made to platform device code yet, for clarity these will be
> posted in a separate series after this one gets applied.
> 
> Changes from v3:
> 
>   - Do not use KBUILD_MODNAME as backlight device name as it breaks
>     userspace interface ("fujitsu-laptop" vs. "fujitsu_laptop").
> 
> Changes from v2:
> 
>   - Patch 2/4 from v2 did not work as expected and was thus replaced
>     with a rebased version of patch 3/4 from v1.
> 
>   - Added a check in patch 3/4 to prevent a NULL dereference when
>     ACPI device FUJ02B1 is not present and ACPI device FUJ02E3 is.
> 
> Changes from v1:
> 
>   - Rebase on top of reworked Alan Jenkins' cleanup patch series.
> 
>   - Drop patch 1/4 from v1 as it has already been applied in reworked
>     Alan Jenkins' cleanup patch series.
> 
>   - Patch 3/4 from v1 has been replaced with a completely different one
>     (patch 2/4).  It needs to be tested on a relevant machine as it is
>     based purely on a dump of a DSDT table (further details can be found
>     in the patch itself).
> 
>   - Patch 3/4 in v2 is a rebased version of patch 8/10 from the reworked
>     Alan Jenkins' cleanup patch series.  Patch 2/4 from v2 (the one
>     mentioned in the previous bullet point) ensures this one can be
>     safely applied without causing a NULL dereference under any
>     circumstances.
> 
>  drivers/platform/x86/fujitsu-laptop.c | 98 ++++++++++++++++++-----------------
>  1 file changed, 50 insertions(+), 48 deletions(-)

As noted, this V4 patch series is identical to V3 except for the backlight
device name fix.  No regressions are evident on the hardware I have (S7020). 
I am therefore happy to see this series applied.  It represents a further
worthwhile improvement to the fujitsu-laptop driver which will facilitate
future maintenance and provide a more consistent basis for upcoming
improvements.

Tested-by: Jonathan Woithe <jwoithe@just42.net>
Reviewed-by: Jonathan Woithe <jwoithe@just42.net>

Regards
  jonathan

[toc] | [prev] | [next] | [standalone]


#1599549

FromAndy Shevchenko <andy.shevchenko@gmail.com>
Date2017-03-13 17:10 +0100
Message-ID<tkAHM-2Z7-17@gated-at.bofh.it>
In reply to#1597110
On Fri, Mar 10, 2017 at 1:02 PM, Jonathan Woithe <jwoithe@just42.net> wrote:
> On Fri, Mar 10, 2017 at 11:50:32AM +0100, Micha?? K??pie?? wrote:
>> These patches should make fujitsu_init() a bit more palatable.  No
>> changes are made to platform device code yet, for clarity these will be
>> posted in a separate series after this one gets applied.

> As noted, this V4 patch series is identical to V3 except for the backlight
> device name fix.  No regressions are evident on the hardware I have (S7020).
> I am therefore happy to see this series applied.  It represents a further
> worthwhile improvement to the fujitsu-laptop driver which will facilitate
> future maintenance and provide a more consistent basis for upcoming
> improvements.
>
> Tested-by: Jonathan Woithe <jwoithe@just42.net>
> Reviewed-by: Jonathan Woithe <jwoithe@just42.net>

Pushed to testing, thanks!

-- 
With Best Regards,
Andy Shevchenko

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web