From a823c26790467da8504f116c725d092d7ac88588 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 31 Oct 2014 09:16:51 -0700 Subject: Input: altera_ps2 - switch to using managed resources Use them devm_ managed resources API to simplify error handling in altera_ps2_probe() and to reduce the size of altera_ps2_remove() and the ps2if struct. Signed-off-by: Tobias Klauser Signed-off-by: Dmitry Torokhov --- drivers/input/serio/altera_ps2.c | 81 ++++++++++++---------------------------- 1 file changed, 24 insertions(+), 57 deletions(-) (limited to 'drivers/input/serio') diff --git a/drivers/input/serio/altera_ps2.c b/drivers/input/serio/altera_ps2.c index cce69d6b9587..b74fc2fef869 100644 --- a/drivers/input/serio/altera_ps2.c +++ b/drivers/input/serio/altera_ps2.c @@ -24,9 +24,7 @@ struct ps2if { struct serio *io; - struct resource *iomem_res; void __iomem *base; - unsigned irq; }; /* @@ -83,16 +81,34 @@ static void altera_ps2_close(struct serio *io) static int altera_ps2_probe(struct platform_device *pdev) { struct ps2if *ps2if; + struct resource *res; struct serio *serio; int error, irq; - ps2if = kzalloc(sizeof(struct ps2if), GFP_KERNEL); - serio = kzalloc(sizeof(struct serio), GFP_KERNEL); - if (!ps2if || !serio) { - error = -ENOMEM; - goto err_free_mem; + ps2if = devm_kzalloc(&pdev->dev, sizeof(struct ps2if), GFP_KERNEL); + if (!ps2if) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + ps2if->base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(ps2if->base)) + return PTR_ERR(ps2if->base); + + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return -ENXIO; + + error = devm_request_irq(&pdev->dev, irq, altera_ps2_rxint, 0, + pdev->name, ps2if); + if (error) { + dev_err(&pdev->dev, "could not request IRQ %d\n", irq); + return error; } + serio = kzalloc(sizeof(struct serio), GFP_KERNEL); + if (!serio) + return -ENOMEM; + serio->id.type = SERIO_8042; serio->write = altera_ps2_write; serio->open = altera_ps2_open; @@ -103,56 +119,12 @@ static int altera_ps2_probe(struct platform_device *pdev) serio->dev.parent = &pdev->dev; ps2if->io = serio; - ps2if->iomem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (ps2if->iomem_res == NULL) { - error = -ENOENT; - goto err_free_mem; - } - - - irq = platform_get_irq(pdev, 0); - if (irq < 0) { - error = -ENXIO; - goto err_free_mem; - } - ps2if->irq = irq; - - if (!request_mem_region(ps2if->iomem_res->start, - resource_size(ps2if->iomem_res), pdev->name)) { - error = -EBUSY; - goto err_free_mem; - } - - ps2if->base = ioremap(ps2if->iomem_res->start, - resource_size(ps2if->iomem_res)); - if (!ps2if->base) { - error = -ENOMEM; - goto err_free_res; - } - - error = request_irq(ps2if->irq, altera_ps2_rxint, 0, pdev->name, ps2if); - if (error) { - dev_err(&pdev->dev, "could not allocate IRQ %d: %d\n", - ps2if->irq, error); - goto err_unmap; - } - - dev_info(&pdev->dev, "base %p, irq %d\n", ps2if->base, ps2if->irq); + dev_info(&pdev->dev, "base %p, irq %d\n", ps2if->base, irq); serio_register_port(ps2if->io); platform_set_drvdata(pdev, ps2if); return 0; - - err_unmap: - iounmap(ps2if->base); - err_free_res: - release_mem_region(ps2if->iomem_res->start, - resource_size(ps2if->iomem_res)); - err_free_mem: - kfree(ps2if); - kfree(serio); - return error; } /* @@ -163,11 +135,6 @@ static int altera_ps2_remove(struct platform_device *pdev) struct ps2if *ps2if = platform_get_drvdata(pdev); serio_unregister_port(ps2if->io); - free_irq(ps2if->irq, ps2if); - iounmap(ps2if->base); - release_mem_region(ps2if->iomem_res->start, - resource_size(ps2if->iomem_res)); - kfree(ps2if); return 0; } -- cgit v1.2.3-70-g09d2 From 8195077c4a93486f715edac3e9f1503df7dec60a Mon Sep 17 00:00:00 2001 From: Todor Minchev Date: Tue, 2 Dec 2014 15:16:39 -0800 Subject: Input: i8042 - do not try to load on Intel NUC D54250WYK The Intel NUC D54250WYK has no PS/2 controller, however the DSDT declares PS/2 devices which trigger the loading of the i8042 driver. Signed-off-by: Todor Minchev Signed-off-by: Dmitry Torokhov --- drivers/input/serio/i8042-x86ia64io.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'drivers/input/serio') diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h index a0bcbb64d06d..a26366a263a5 100644 --- a/drivers/input/serio/i8042-x86ia64io.h +++ b/drivers/input/serio/i8042-x86ia64io.h @@ -313,6 +313,16 @@ static const struct dmi_system_id __initconst i8042_dmi_nopnp_table[] = { DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"), }, }, + { + /* + * Intel NUC D54250WYK - does not have i8042 controller but + * declares PS/2 devices in DSDT. + */ + .matches = { + DMI_MATCH(DMI_BOARD_NAME, "D54250WYK"), + DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"), + }, + }, { /* MSI Wind U-100 */ .matches = { -- cgit v1.2.3-70-g09d2 From 939ffb1712890ee22146d2dfc24adbc7da6afa84 Mon Sep 17 00:00:00 2001 From: Aniroop Mathur Date: Wed, 3 Dec 2014 14:27:42 -0800 Subject: Input: initialize device counter variables with -1 Let's initialize atomic_t variables keeping track of number of various devices created so far with -1 in order to avoid extra subtraction operation. Signed-off-by: Aniroop Mathur Signed-off-by: Dmitry Torokhov --- drivers/input/gameport/gameport.c | 4 ++-- drivers/input/joystick/xpad.c | 8 ++++---- drivers/input/misc/ims-pcu.c | 4 ++-- drivers/input/serio/serio.c | 4 ++-- drivers/input/serio/serio_raw.c | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) (limited to 'drivers/input/serio') diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c index e29c04e2aff4..e853a2134680 100644 --- a/drivers/input/gameport/gameport.c +++ b/drivers/input/gameport/gameport.c @@ -527,14 +527,14 @@ EXPORT_SYMBOL(gameport_set_phys); */ static void gameport_init_port(struct gameport *gameport) { - static atomic_t gameport_no = ATOMIC_INIT(0); + static atomic_t gameport_no = ATOMIC_INIT(-1); __module_get(THIS_MODULE); mutex_init(&gameport->drv_mutex); device_initialize(&gameport->dev); dev_set_name(&gameport->dev, "gameport%lu", - (unsigned long)atomic_inc_return(&gameport_no) - 1); + (unsigned long)atomic_inc_return(&gameport_no)); gameport->dev.bus = &gameport_bus; gameport->dev.release = gameport_release_port; if (gameport->parent) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index cd13c82ca0a1..36281eeabb19 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -884,8 +884,8 @@ static void xpad_led_set(struct led_classdev *led_cdev, static int xpad_led_probe(struct usb_xpad *xpad) { - static atomic_t led_seq = ATOMIC_INIT(0); - long led_no; + static atomic_t led_seq = ATOMIC_INIT(-1); + unsigned long led_no; struct xpad_led *led; struct led_classdev *led_cdev; int error; @@ -897,9 +897,9 @@ static int xpad_led_probe(struct usb_xpad *xpad) if (!led) return -ENOMEM; - led_no = (long)atomic_inc_return(&led_seq) - 1; + led_no = atomic_inc_return(&led_seq); - snprintf(led->name, sizeof(led->name), "xpad%ld", led_no); + snprintf(led->name, sizeof(led->name), "xpad%lu", led_no); led->xpad = xpad; led_cdev = &led->led_cdev; diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c index 719410feb84b..69caee906ecd 100644 --- a/drivers/input/misc/ims-pcu.c +++ b/drivers/input/misc/ims-pcu.c @@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id) static int ims_pcu_init_application_mode(struct ims_pcu *pcu) { - static atomic_t device_no = ATOMIC_INIT(0); + static atomic_t device_no = ATOMIC_INIT(-1); const struct ims_pcu_device_info *info; int error; @@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu) } /* Device appears to be operable, complete initialization */ - pcu->device_no = atomic_inc_return(&device_no) - 1; + pcu->device_no = atomic_inc_return(&device_no); /* * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c index d399b8b0f000..a05a5179da32 100644 --- a/drivers/input/serio/serio.c +++ b/drivers/input/serio/serio.c @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev) */ static void serio_init_port(struct serio *serio) { - static atomic_t serio_no = ATOMIC_INIT(0); + static atomic_t serio_no = ATOMIC_INIT(-1); __module_get(THIS_MODULE); @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio) mutex_init(&serio->drv_mutex); device_initialize(&serio->dev); dev_set_name(&serio->dev, "serio%lu", - (unsigned long)atomic_inc_return(&serio_no) - 1); + (unsigned long)atomic_inc_return(&serio_no)); serio->dev.bus = &serio_bus; serio->dev.release = serio_release_port; serio->dev.groups = serio_device_attr_groups; diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c index c9a02fe57576..71ef5d65a0c6 100644 --- a/drivers/input/serio/serio_raw.c +++ b/drivers/input/serio/serio_raw.c @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data, static int serio_raw_connect(struct serio *serio, struct serio_driver *drv) { - static atomic_t serio_raw_no = ATOMIC_INIT(0); + static atomic_t serio_raw_no = ATOMIC_INIT(-1); struct serio_raw *serio_raw; int err; @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv) } snprintf(serio_raw->name, sizeof(serio_raw->name), - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1); + "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no)); kref_init(&serio_raw->kref); INIT_LIST_HEAD(&serio_raw->client_list); init_waitqueue_head(&serio_raw->wait); -- cgit v1.2.3-70-g09d2