Linux Input/HID development
 help / color / mirror / Atom feed
* [PATCH] Input: atlas_btns - modernize the driver
@ 2026-05-30  5:52 Dmitry Torokhov
  0 siblings, 0 replies; only message in thread
From: Dmitry Torokhov @ 2026-05-30  5:52 UTC (permalink / raw)
  To: linux-input; +Cc: Rafael J. Wysocki, linux-kernel

Rework the driver to use modern style:

- Remove global state by introducing a per-device structure
- Use devm for resource management (input device allocation)
- Use dev_err_probe() for error reporting in the probe path
- Clean up unused definitions and headers.

Assisted-by: Gemini:gemini-3.1-pro
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/misc/atlas_btns.c | 109 ++++++++++++++++----------------
 1 file changed, 55 insertions(+), 54 deletions(-)

diff --git a/drivers/input/misc/atlas_btns.c b/drivers/input/misc/atlas_btns.c
index 835ad45a9d65..5805a1a3bb05 100644
--- a/drivers/input/misc/atlas_btns.c
+++ b/drivers/input/misc/atlas_btns.c
@@ -15,17 +15,18 @@
 #include <linux/types.h>
 #include <linux/acpi.h>
 #include <linux/platform_device.h>
-#include <linux/uaccess.h>
 
 #define ACPI_ATLAS_NAME		"Atlas ACPI"
-#define ACPI_ATLAS_CLASS	"Atlas"
 
-static unsigned short atlas_keymap[16];
-static struct input_dev *input_dev;
+struct atlas_btns {
+	struct input_dev *input_dev;
+	unsigned short keymap[16];
+};
 
 /* button handling code */
 static acpi_status acpi_atlas_button_setup(acpi_handle region_handle,
-		    u32 function, void *handler_context, void **return_context)
+					   u32 function, void *handler_context,
+					   void **return_context)
 {
 	*return_context =
 		(function != ACPI_REGION_DEACTIVATE) ? handler_context : NULL;
@@ -34,33 +35,37 @@ static acpi_status acpi_atlas_button_setup(acpi_handle region_handle,
 }
 
 static acpi_status acpi_atlas_button_handler(u32 function,
-		      acpi_physical_address address,
-		      u32 bit_width, u64 *value,
-		      void *handler_context, void *region_context)
+					     acpi_physical_address address,
+					     u32 bit_width, u64 *value,
+					     void *handler_context,
+					     void *region_context)
 {
-	acpi_status status;
+	struct atlas_btns *atlas = region_context;
 
 	if (function == ACPI_WRITE) {
 		int code = address & 0x0f;
 		int key_down = !(address & 0x10);
 
-		input_event(input_dev, EV_MSC, MSC_SCAN, code);
-		input_report_key(input_dev, atlas_keymap[code], key_down);
-		input_sync(input_dev);
+		input_event(atlas->input_dev, EV_MSC, MSC_SCAN, code);
+		input_report_key(atlas->input_dev, atlas->keymap[code],
+				 key_down);
+		input_sync(atlas->input_dev);
 
-		status = AE_OK;
-	} else {
-		pr_warn("shrugged on unexpected function: function=%x,address=%lx,value=%x\n",
-			function, (unsigned long)address, (u32)*value);
-		status = AE_BAD_PARAMETER;
+		return AE_OK;
 	}
 
-	return status;
+	dev_warn(atlas->input_dev->dev.parent,
+		 "unexpected function: function=%x,address=%lx,value=%x\n",
+		 function, (unsigned long)address, (u32)*value);
+
+	return AE_BAD_PARAMETER;
 }
 
 static int atlas_acpi_button_probe(struct platform_device *pdev)
 {
 	struct acpi_device *device;
+	struct atlas_btns *atlas;
+	struct input_dev *input_dev;
 	acpi_status status;
 	int i;
 	int err;
@@ -69,65 +74,62 @@ static int atlas_acpi_button_probe(struct platform_device *pdev)
 	if (!device)
 		return -ENODEV;
 
-	input_dev = input_allocate_device();
-	if (!input_dev) {
-		pr_err("unable to allocate input device\n");
+	atlas = devm_kzalloc(&pdev->dev, sizeof(*atlas), GFP_KERNEL);
+	if (!atlas)
 		return -ENOMEM;
-	}
+
+	input_dev = devm_input_allocate_device(&pdev->dev);
+	if (!input_dev)
+		return -ENOMEM;
+
+	atlas->input_dev = input_dev;
 
 	input_dev->name = "Atlas ACPI button driver";
 	input_dev->phys = "ASIM0000/atlas/input0";
 	input_dev->id.bustype = BUS_HOST;
-	input_dev->keycode = atlas_keymap;
-	input_dev->keycodesize = sizeof(unsigned short);
-	input_dev->keycodemax = ARRAY_SIZE(atlas_keymap);
+	input_dev->keycode = atlas->keymap;
+	input_dev->keycodesize = sizeof(atlas->keymap[0]);
+	input_dev->keycodemax = ARRAY_SIZE(atlas->keymap);
 
 	input_set_capability(input_dev, EV_MSC, MSC_SCAN);
-	__set_bit(EV_KEY, input_dev->evbit);
-	for (i = 0; i < ARRAY_SIZE(atlas_keymap); i++) {
+	for (i = 0; i < ARRAY_SIZE(atlas->keymap); i++) {
 		if (i < 9) {
-			atlas_keymap[i] = KEY_F1 + i;
-			__set_bit(KEY_F1 + i, input_dev->keybit);
-		} else
-			atlas_keymap[i] = KEY_RESERVED;
+			atlas->keymap[i] = KEY_F1 + i;
+			input_set_capability(input_dev, EV_KEY, KEY_F1 + i);
+		} else {
+			atlas->keymap[i] = KEY_RESERVED;
+		}
 	}
 
 	err = input_register_device(input_dev);
-	if (err) {
-		pr_err("couldn't register input device\n");
-		input_free_device(input_dev);
-		return err;
-	}
+	if (err)
+		return dev_err_probe(&pdev->dev, err,
+				     "couldn't register input device\n");
 
 	/* hookup button handler */
 	status = acpi_install_address_space_handler(device->handle,
-				0x81, &acpi_atlas_button_handler,
-				&acpi_atlas_button_setup, device);
-	if (ACPI_FAILURE(status)) {
-		pr_err("error installing addr spc handler\n");
-		input_unregister_device(input_dev);
-		err = -EINVAL;
-	}
+						    0x81,
+						    &acpi_atlas_button_handler,
+						    &acpi_atlas_button_setup,
+						    atlas);
+	if (ACPI_FAILURE(status))
+		return dev_err_probe(&pdev->dev, -EINVAL,
+				     "error installing addr spc handler\n");
 
-	return err;
+	return 0;
 }
 
 static void atlas_acpi_button_remove(struct platform_device *pdev)
 {
 	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
-	acpi_status status;
 
-	status = acpi_remove_address_space_handler(device->handle,
-				0x81, &acpi_atlas_button_handler);
-	if (ACPI_FAILURE(status))
-		pr_err("error removing addr spc handler\n");
-
-	input_unregister_device(input_dev);
+	acpi_remove_address_space_handler(device->handle, 0x81,
+					  &acpi_atlas_button_handler);
 }
 
 static const struct acpi_device_id atlas_device_ids[] = {
-	{"ASIM0000", 0},
-	{"", 0},
+	{ "ASIM0000" },
+	{ "" }
 };
 MODULE_DEVICE_TABLE(acpi, atlas_device_ids);
 
@@ -144,4 +146,3 @@ module_platform_driver(atlas_acpi_driver);
 MODULE_AUTHOR("Jaya Kumar");
 MODULE_LICENSE("GPL");
 MODULE_DESCRIPTION("Atlas button driver");
-
-- 
2.54.0.823.g6e5bcc1fc9-goog


-- 
Dmitry

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-05-30  5:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-30  5:52 [PATCH] Input: atlas_btns - modernize the driver Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox