From dc2f1423f056f26144f60b089430e193a4dfc672 Mon Sep 17 00:00:00 2001 From: Erick Archer Date: Sun, 2 Jun 2024 21:30:36 -0700 Subject: Input: mouse - use sizeof(*pointer) instead of sizeof(type) It is preferred to use sizeof(*pointer) instead of sizeof(type) due to the type of the variable can change and one needs not change the former (unlike the latter). This patch has no effect on runtime behavior. Signed-off-by: Erick Archer Link: https://lore.kernel.org/r/AS8PR02MB7237FB736DBF67A58798FDF38BFE2@AS8PR02MB7237.eurprd02.prod.outlook.com Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/alps.c | 2 +- drivers/input/mouse/appletouch.c | 2 +- drivers/input/mouse/bcm5974.c | 2 +- drivers/input/mouse/cypress_ps2.c | 2 +- drivers/input/mouse/focaltech.c | 3 +-- drivers/input/mouse/hgpk.c | 2 +- drivers/input/mouse/lifebook.c | 2 +- drivers/input/mouse/maplemouse.c | 2 +- drivers/input/mouse/psmouse-base.c | 2 +- drivers/input/mouse/sentelic.c | 2 +- drivers/input/mouse/sermouse.c | 2 +- drivers/input/mouse/synaptics.c | 4 ++-- drivers/input/mouse/synaptics_i2c.c | 2 +- drivers/input/mouse/vsxxxaa.c | 2 +- 14 files changed, 15 insertions(+), 16 deletions(-) (limited to 'drivers/input/mouse') diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c index e2c11d9f3868..d5ef5a112d6f 100644 --- a/drivers/input/mouse/alps.c +++ b/drivers/input/mouse/alps.c @@ -3201,7 +3201,7 @@ int alps_detect(struct psmouse *psmouse, bool set_properties) */ psmouse_reset(psmouse); - priv = kzalloc(sizeof(struct alps_data), GFP_KERNEL); + priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; diff --git a/drivers/input/mouse/appletouch.c b/drivers/input/mouse/appletouch.c index 627048bc6a12..e669f86f1882 100644 --- a/drivers/input/mouse/appletouch.c +++ b/drivers/input/mouse/appletouch.c @@ -855,7 +855,7 @@ static int atp_probe(struct usb_interface *iface, } /* allocate memory for our device state and initialize it */ - dev = kzalloc(sizeof(struct atp), GFP_KERNEL); + dev = kzalloc(sizeof(*dev), GFP_KERNEL); input_dev = input_allocate_device(); if (!dev || !input_dev) { dev_err(&iface->dev, "Out of memory\n"); diff --git a/drivers/input/mouse/bcm5974.c b/drivers/input/mouse/bcm5974.c index ca150618d32f..10a03a566905 100644 --- a/drivers/input/mouse/bcm5974.c +++ b/drivers/input/mouse/bcm5974.c @@ -904,7 +904,7 @@ static int bcm5974_probe(struct usb_interface *iface, cfg = bcm5974_get_config(udev); /* allocate memory for our device state and initialize it */ - dev = kzalloc(sizeof(struct bcm5974), GFP_KERNEL); + dev = kzalloc(sizeof(*dev), GFP_KERNEL); input_dev = input_allocate_device(); if (!dev || !input_dev) { dev_err(&iface->dev, "out of memory\n"); diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c index d272f1ec27ba..c693130bef41 100644 --- a/drivers/input/mouse/cypress_ps2.c +++ b/drivers/input/mouse/cypress_ps2.c @@ -659,7 +659,7 @@ int cypress_init(struct psmouse *psmouse) { struct cytp_data *cytp; - cytp = kzalloc(sizeof(struct cytp_data), GFP_KERNEL); + cytp = kzalloc(sizeof(*cytp), GFP_KERNEL); if (!cytp) return -ENOMEM; diff --git a/drivers/input/mouse/focaltech.c b/drivers/input/mouse/focaltech.c index c74b99077d16..356b99d48544 100644 --- a/drivers/input/mouse/focaltech.c +++ b/drivers/input/mouse/focaltech.c @@ -408,8 +408,7 @@ int focaltech_init(struct psmouse *psmouse) struct focaltech_data *priv; int error; - psmouse->private = priv = kzalloc(sizeof(struct focaltech_data), - GFP_KERNEL); + psmouse->private = priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; diff --git a/drivers/input/mouse/hgpk.c b/drivers/input/mouse/hgpk.c index 3c8310da0b05..6125652e5ad8 100644 --- a/drivers/input/mouse/hgpk.c +++ b/drivers/input/mouse/hgpk.c @@ -981,7 +981,7 @@ int hgpk_init(struct psmouse *psmouse) struct hgpk_data *priv; int err; - priv = kzalloc(sizeof(struct hgpk_data), GFP_KERNEL); + priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) { err = -ENOMEM; goto alloc_fail; diff --git a/drivers/input/mouse/lifebook.c b/drivers/input/mouse/lifebook.c index bd9955730176..7147dacc404f 100644 --- a/drivers/input/mouse/lifebook.c +++ b/drivers/input/mouse/lifebook.c @@ -273,7 +273,7 @@ static int lifebook_create_relative_device(struct psmouse *psmouse) struct lifebook_data *priv; int error = -ENOMEM; - priv = kzalloc(sizeof(struct lifebook_data), GFP_KERNEL); + priv = kzalloc(sizeof(*priv), GFP_KERNEL); dev2 = input_allocate_device(); if (!priv || !dev2) goto err_out; diff --git a/drivers/input/mouse/maplemouse.c b/drivers/input/mouse/maplemouse.c index 2de64d6a04d1..baef4be14b54 100644 --- a/drivers/input/mouse/maplemouse.c +++ b/drivers/input/mouse/maplemouse.c @@ -73,7 +73,7 @@ static int probe_maple_mouse(struct device *dev) struct input_dev *input_dev; struct dc_mouse *mse; - mse = kzalloc(sizeof(struct dc_mouse), GFP_KERNEL); + mse = kzalloc(sizeof(*mse), GFP_KERNEL); if (!mse) { error = -ENOMEM; goto fail; diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c index a0aac76b1e41..a2c9f7144864 100644 --- a/drivers/input/mouse/psmouse-base.c +++ b/drivers/input/mouse/psmouse-base.c @@ -1591,7 +1591,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv) psmouse_deactivate(parent); } - psmouse = kzalloc(sizeof(struct psmouse), GFP_KERNEL); + psmouse = kzalloc(sizeof(*psmouse), GFP_KERNEL); input_dev = input_allocate_device(); if (!psmouse || !input_dev) goto err_free; diff --git a/drivers/input/mouse/sentelic.c b/drivers/input/mouse/sentelic.c index 2716d2ba386a..44b136fc29aa 100644 --- a/drivers/input/mouse/sentelic.c +++ b/drivers/input/mouse/sentelic.c @@ -1028,7 +1028,7 @@ int fsp_init(struct psmouse *psmouse) "Finger Sensing Pad, hw: %d.%d.%d, sn: %x, sw: %s\n", ver >> 4, ver & 0x0F, rev, sn, fsp_drv_ver); - psmouse->private = priv = kzalloc(sizeof(struct fsp_data), GFP_KERNEL); + psmouse->private = priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; diff --git a/drivers/input/mouse/sermouse.c b/drivers/input/mouse/sermouse.c index 993f90333380..218c8432a13b 100644 --- a/drivers/input/mouse/sermouse.c +++ b/drivers/input/mouse/sermouse.c @@ -231,7 +231,7 @@ static int sermouse_connect(struct serio *serio, struct serio_driver *drv) unsigned char c = serio->id.extra; int err = -ENOMEM; - sermouse = kzalloc(sizeof(struct sermouse), GFP_KERNEL); + sermouse = kzalloc(sizeof(*sermouse), GFP_KERNEL); input_dev = input_allocate_device(); if (!sermouse || !input_dev) goto fail1; diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c index 7a303a9d6bf7..38191c3b31bf 100644 --- a/drivers/input/mouse/synaptics.c +++ b/drivers/input/mouse/synaptics.c @@ -708,7 +708,7 @@ static void synaptics_pt_create(struct psmouse *psmouse) { struct serio *serio; - serio = kzalloc(sizeof(struct serio), GFP_KERNEL); + serio = kzalloc(sizeof(*serio), GFP_KERNEL); if (!serio) { psmouse_err(psmouse, "not enough memory for pass-through port\n"); @@ -1563,7 +1563,7 @@ static int synaptics_init_ps2(struct psmouse *psmouse, synaptics_apply_quirks(psmouse, info); - psmouse->private = priv = kzalloc(sizeof(struct synaptics_data), GFP_KERNEL); + psmouse->private = priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; diff --git a/drivers/input/mouse/synaptics_i2c.c b/drivers/input/mouse/synaptics_i2c.c index 56e9ba396858..a0d707e47d93 100644 --- a/drivers/input/mouse/synaptics_i2c.c +++ b/drivers/input/mouse/synaptics_i2c.c @@ -508,7 +508,7 @@ static struct synaptics_i2c *synaptics_i2c_touch_create(struct i2c_client *clien { struct synaptics_i2c *touch; - touch = kzalloc(sizeof(struct synaptics_i2c), GFP_KERNEL); + touch = kzalloc(sizeof(*touch), GFP_KERNEL); if (!touch) return NULL; diff --git a/drivers/input/mouse/vsxxxaa.c b/drivers/input/mouse/vsxxxaa.c index 8af8e4a15f95..707cd28f4ba6 100644 --- a/drivers/input/mouse/vsxxxaa.c +++ b/drivers/input/mouse/vsxxxaa.c @@ -456,7 +456,7 @@ static int vsxxxaa_connect(struct serio *serio, struct serio_driver *drv) struct input_dev *input_dev; int err = -ENOMEM; - mouse = kzalloc(sizeof(struct vsxxxaa), GFP_KERNEL); + mouse = kzalloc(sizeof(*mouse), GFP_KERNEL); input_dev = input_allocate_device(); if (!mouse || !input_dev) goto fail1; -- cgit v1.2.3 From 5f82c1e04721e7cd98e604eb4e58f0724d8e5a65 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Thu, 6 Jun 2024 23:02:48 -0700 Subject: Input: elan_i2c - do not leave interrupt disabled on suspend failure Make sure interrupts are not left disabled when we fail to suspend the touch controller. Fixes: 6696777c6506 ("Input: add driver for Elan I2C/SMbus touchpad") Link: https://lore.kernel.org/r/ZmKiiL-1wzKrhqBj@google.com Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/elan_i2c_core.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/input/mouse') diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c index c2aec5c360b3..ce96513b34f6 100644 --- a/drivers/input/mouse/elan_i2c_core.c +++ b/drivers/input/mouse/elan_i2c_core.c @@ -1356,6 +1356,8 @@ static int elan_suspend(struct device *dev) } err: + if (ret) + enable_irq(client->irq); mutex_unlock(&data->sysfs_mutex); return ret; } -- cgit v1.2.3 From c1a339001191e60f70c4da827569b3bb27500a9a Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 28 Jun 2024 15:47:23 -0700 Subject: Input: cypress_ps2 - clean up setting reporting rate Casting an integer field containing desired rate to a pointer to bytes works on little endian architectures where the driver is used, but not a good practice. Use a temporary of proper type instead. Link: https://lore.kernel.org/r/20240628224728.2180126-1-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/cypress_ps2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/input/mouse') diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c index c693130bef41..32b55b2b9b76 100644 --- a/drivers/input/mouse/cypress_ps2.c +++ b/drivers/input/mouse/cypress_ps2.c @@ -612,6 +612,7 @@ static psmouse_ret_t cypress_protocol_handler(struct psmouse *psmouse) static void cypress_set_rate(struct psmouse *psmouse, unsigned int rate) { struct cytp_data *cytp = psmouse->private; + u8 rate_param; if (rate >= 80) { psmouse->rate = 80; @@ -621,8 +622,8 @@ static void cypress_set_rate(struct psmouse *psmouse, unsigned int rate) cytp->mode &= ~CYTP_BIT_HIGH_RATE; } - ps2_command(&psmouse->ps2dev, (unsigned char *)&psmouse->rate, - PSMOUSE_CMD_SETRATE); + rate_param = (u8)rate; + ps2_command(&psmouse->ps2dev, &rate_param, PSMOUSE_CMD_SETRATE); } static void cypress_disconnect(struct psmouse *psmouse) -- cgit v1.2.3 From e8688b93ce00230614406d189e8286315832469a Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 28 Jun 2024 15:47:24 -0700 Subject: Input: cypress_ps2 - fix error handling when sending command fails Stop layering error handling in cypress_ps2_sendbyte() and simply pass on error code from ps2_sendbyte() and use it in the callers. This fixes mishandling of error condition in cypress_ps2_read_cmd_status() which expects errors to be negative. Reported-by: Igor Artemiev Link: https://lore.kernel.org/r/20240628224728.2180126-2-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/cypress_ps2.c | 32 +++++++++++++++----------------- drivers/input/mouse/cypress_ps2.h | 6 ------ 2 files changed, 15 insertions(+), 23 deletions(-) (limited to 'drivers/input/mouse') diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c index 32b55b2b9b76..fcc3921e49e0 100644 --- a/drivers/input/mouse/cypress_ps2.c +++ b/drivers/input/mouse/cypress_ps2.c @@ -38,15 +38,14 @@ static const unsigned char cytp_resolution[] = {0x00, 0x01, 0x02, 0x03}; static int cypress_ps2_sendbyte(struct psmouse *psmouse, int value) { struct ps2dev *ps2dev = &psmouse->ps2dev; + int error; - if (ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT) < 0) { + error = ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT); + if (error) { psmouse_dbg(psmouse, - "sending command 0x%02x failed, resp 0x%02x\n", - value & 0xff, ps2dev->nak); - if (ps2dev->nak == CYTP_PS2_RETRY) - return CYTP_PS2_RETRY; - else - return CYTP_PS2_ERROR; + "sending command 0x%02x failed, resp 0x%02x, error %d\n", + value & 0xff, ps2dev->nak, error); + return error; } #ifdef CYTP_DEBUG_VERBOSE @@ -73,21 +72,20 @@ static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd, * to make the device return to the ready state. */ rc = cypress_ps2_sendbyte(psmouse, cmd & 0xff); - if (rc == CYTP_PS2_RETRY) { + if (rc == -EAGAIN) { rc = cypress_ps2_sendbyte(psmouse, 0x00); - if (rc == CYTP_PS2_RETRY) + if (rc == -EAGAIN) rc = cypress_ps2_sendbyte(psmouse, 0x0a); } - if (rc == CYTP_PS2_ERROR) - continue; - rc = cypress_ps2_sendbyte(psmouse, data); - if (rc == CYTP_PS2_RETRY) + if (!rc) { rc = cypress_ps2_sendbyte(psmouse, data); - if (rc == CYTP_PS2_ERROR) - continue; - else - break; + if (rc == -EAGAIN) + rc = cypress_ps2_sendbyte(psmouse, data); + + if (!rc) + break; + } } while (--tries > 0); ps2_end_command(ps2dev); diff --git a/drivers/input/mouse/cypress_ps2.h b/drivers/input/mouse/cypress_ps2.h index bb4979d06bf9..47d538a49089 100644 --- a/drivers/input/mouse/cypress_ps2.h +++ b/drivers/input/mouse/cypress_ps2.h @@ -72,12 +72,6 @@ #define CYTP_DATA_TIMEOUT 30 #define CYTP_EXT_CMD 0xe8 -#define CYTP_PS2_RETRY 0xfe -#define CYTP_PS2_ERROR 0xfc - -#define CYTP_RESP_RETRY 0x01 -#define CYTP_RESP_ERROR 0xfe - #define CYTP_105001_WIDTH 97 /* Dell XPS 13 */ #define CYTP_105001_HIGH 59 -- cgit v1.2.3 From 8bccf667f62a2351fd0b2a2fe5ba90806702c048 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 28 Jun 2024 15:47:25 -0700 Subject: Input: cypress_ps2 - report timeouts when reading command status Report -ETIMEDOUT error code from cypress_ps2_read_cmd_status() when device does not send enough data within the allotted time in response to a command. Link: https://lore.kernel.org/r/20240628224728.2180126-3-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/cypress_ps2.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'drivers/input/mouse') diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c index fcc3921e49e0..8e17cd0bc437 100644 --- a/drivers/input/mouse/cypress_ps2.c +++ b/drivers/input/mouse/cypress_ps2.c @@ -115,9 +115,12 @@ static int cypress_ps2_read_cmd_status(struct psmouse *psmouse, if (rc < 0) goto out; - wait_event_timeout(ps2dev->wait, - (psmouse->pktcnt >= pktsize), - msecs_to_jiffies(CYTP_CMD_TIMEOUT)); + if (!wait_event_timeout(ps2dev->wait, + psmouse->pktcnt >= pktsize, + msecs_to_jiffies(CYTP_CMD_TIMEOUT))) { + rc = -ETIMEDOUT; + goto out; + } memcpy(param, psmouse->packet, pktsize); -- cgit v1.2.3 From 93f25f92fc7dda195c3a7ec38d6bc67c1cbed2c6 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 28 Jun 2024 15:47:26 -0700 Subject: Input: cypress_ps2 - propagate errors from lower layers Do not override errors reported by lower layers with generic "-1", but propagate them to the callers. Change the checks for errors to be in the form of "if (error)" to maintain consistency. Link: https://lore.kernel.org/r/20240628224728.2180126-4-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/cypress_ps2.c | 62 ++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 27 deletions(-) (limited to 'drivers/input/mouse') diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c index 8e17cd0bc437..87b87f14e749 100644 --- a/drivers/input/mouse/cypress_ps2.c +++ b/drivers/input/mouse/cypress_ps2.c @@ -97,10 +97,10 @@ static int cypress_ps2_read_cmd_status(struct psmouse *psmouse, unsigned char cmd, unsigned char *param) { - int rc; struct ps2dev *ps2dev = &psmouse->ps2dev; enum psmouse_state old_state; int pktsize; + int rc; ps2_begin_command(ps2dev); @@ -112,7 +112,7 @@ static int cypress_ps2_read_cmd_status(struct psmouse *psmouse, memset(param, 0, pktsize); rc = cypress_ps2_sendbyte(psmouse, 0xe9); - if (rc < 0) + if (rc) goto out; if (!wait_event_timeout(ps2dev->wait, @@ -322,15 +322,15 @@ static int cypress_read_tp_metrics(struct psmouse *psmouse) static int cypress_query_hardware(struct psmouse *psmouse) { - int ret; + int error; - ret = cypress_read_fw_version(psmouse); - if (ret) - return ret; + error = cypress_read_fw_version(psmouse); + if (error) + return error; - ret = cypress_read_tp_metrics(psmouse); - if (ret) - return ret; + error = cypress_read_tp_metrics(psmouse); + if (error) + return error; return 0; } @@ -339,9 +339,12 @@ static int cypress_set_absolute_mode(struct psmouse *psmouse) { struct cytp_data *cytp = psmouse->private; unsigned char param[3]; + int error; - if (cypress_send_ext_cmd(psmouse, CYTP_CMD_ABS_WITH_PRESSURE_MODE, param) < 0) - return -1; + error = cypress_send_ext_cmd(psmouse, CYTP_CMD_ABS_WITH_PRESSURE_MODE, + param); + if (error) + return error; cytp->mode = (cytp->mode & ~CYTP_BIT_ABS_REL_MASK) | CYTP_BIT_ABS_PRESSURE; @@ -366,7 +369,7 @@ static void cypress_reset(struct psmouse *psmouse) static int cypress_set_input_params(struct input_dev *input, struct cytp_data *cytp) { - int ret; + int error; if (!cytp->tp_res_x || !cytp->tp_res_y) return -EINVAL; @@ -383,10 +386,10 @@ static int cypress_set_input_params(struct input_dev *input, input_set_abs_params(input, ABS_MT_POSITION_Y, 0, cytp->tp_max_abs_y, 0, 0); input_set_abs_params(input, ABS_MT_PRESSURE, 0, 255, 0, 0); - ret = input_mt_init_slots(input, CYTP_MAX_MT_SLOTS, - INPUT_MT_DROP_UNUSED|INPUT_MT_TRACK); - if (ret < 0) - return ret; + error = input_mt_init_slots(input, CYTP_MAX_MT_SLOTS, + INPUT_MT_DROP_UNUSED | INPUT_MT_TRACK); + if (error) + return error; __set_bit(INPUT_PROP_SEMI_MT, input->propbit); @@ -637,21 +640,22 @@ static void cypress_disconnect(struct psmouse *psmouse) static int cypress_reconnect(struct psmouse *psmouse) { int tries = CYTP_PS2_CMD_TRIES; - int rc; + int error; do { cypress_reset(psmouse); - rc = cypress_detect(psmouse, false); - } while (rc && (--tries > 0)); + error = cypress_detect(psmouse, false); + } while (error && (--tries > 0)); - if (rc) { + if (error) { psmouse_err(psmouse, "Reconnect: unable to detect trackpad.\n"); - return -1; + return error; } - if (cypress_set_absolute_mode(psmouse)) { + error = cypress_set_absolute_mode(psmouse); + if (error) { psmouse_err(psmouse, "Reconnect: Unable to initialize Cypress absolute mode.\n"); - return -1; + return error; } return 0; @@ -660,6 +664,7 @@ static int cypress_reconnect(struct psmouse *psmouse) int cypress_init(struct psmouse *psmouse) { struct cytp_data *cytp; + int error; cytp = kzalloc(sizeof(*cytp), GFP_KERNEL); if (!cytp) @@ -670,17 +675,20 @@ int cypress_init(struct psmouse *psmouse) cypress_reset(psmouse); - if (cypress_query_hardware(psmouse)) { + error = cypress_query_hardware(psmouse); + if (error) { psmouse_err(psmouse, "Unable to query Trackpad hardware.\n"); goto err_exit; } - if (cypress_set_absolute_mode(psmouse)) { + error = cypress_set_absolute_mode(psmouse); + if (error) { psmouse_err(psmouse, "init: Unable to initialize Cypress absolute mode.\n"); goto err_exit; } - if (cypress_set_input_params(psmouse->dev, cytp) < 0) { + error = cypress_set_input_params(psmouse->dev, cytp); + if (error) { psmouse_err(psmouse, "init: Unable to set input params.\n"); goto err_exit; } @@ -705,5 +713,5 @@ err_exit: psmouse->private = NULL; kfree(cytp); - return -1; + return error; } -- cgit v1.2.3 From 5e13bea78df88c7185ce2f06645a7e4d8a2ba042 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 28 Jun 2024 15:47:27 -0700 Subject: Input: cypress_ps2 - use u8 when dealing with byte data When dealing with byte data use u8 instead of unsigned char or int. Stop layering error handling in cypress_ps2_sendbyte() and simply pass on error code from ps2_sendbyte(). Additionally use u8 instead of unisgned char throughout the code. Link: https://lore.kernel.org/r/20240628224728.2180126-5-dmitry.torokhov@gmail.com Signed-off-by: Dmitry Torokhov --- drivers/input/mouse/cypress_ps2.c | 78 +++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 44 deletions(-) (limited to 'drivers/input/mouse') diff --git a/drivers/input/mouse/cypress_ps2.c b/drivers/input/mouse/cypress_ps2.c index 87b87f14e749..b3c34ebcc4ef 100644 --- a/drivers/input/mouse/cypress_ps2.c +++ b/drivers/input/mouse/cypress_ps2.c @@ -32,32 +32,30 @@ static void cypress_set_packet_size(struct psmouse *psmouse, unsigned int n) cytp->pkt_size = n; } -static const unsigned char cytp_rate[] = {10, 20, 40, 60, 100, 200}; -static const unsigned char cytp_resolution[] = {0x00, 0x01, 0x02, 0x03}; +static const u8 cytp_rate[] = {10, 20, 40, 60, 100, 200}; +static const u8 cytp_resolution[] = {0x00, 0x01, 0x02, 0x03}; -static int cypress_ps2_sendbyte(struct psmouse *psmouse, int value) +static int cypress_ps2_sendbyte(struct psmouse *psmouse, u8 cmd) { struct ps2dev *ps2dev = &psmouse->ps2dev; int error; - error = ps2_sendbyte(ps2dev, value & 0xff, CYTP_CMD_TIMEOUT); + error = ps2_sendbyte(ps2dev, cmd, CYTP_CMD_TIMEOUT); if (error) { psmouse_dbg(psmouse, "sending command 0x%02x failed, resp 0x%02x, error %d\n", - value & 0xff, ps2dev->nak, error); + cmd, ps2dev->nak, error); return error; } #ifdef CYTP_DEBUG_VERBOSE - psmouse_dbg(psmouse, "sending command 0x%02x succeeded, resp 0xfa\n", - value & 0xff); + psmouse_dbg(psmouse, "sending command 0x%02x succeeded\n", cmd); #endif return 0; } -static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd, - unsigned char data) +static int cypress_ps2_ext_cmd(struct psmouse *psmouse, u8 prefix, u8 nibble) { struct ps2dev *ps2dev = &psmouse->ps2dev; int tries = CYTP_PS2_CMD_TRIES; @@ -71,7 +69,7 @@ static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd, * If sending the command fails, send recovery command * to make the device return to the ready state. */ - rc = cypress_ps2_sendbyte(psmouse, cmd & 0xff); + rc = cypress_ps2_sendbyte(psmouse, prefix); if (rc == -EAGAIN) { rc = cypress_ps2_sendbyte(psmouse, 0x00); if (rc == -EAGAIN) @@ -79,9 +77,9 @@ static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd, } if (!rc) { - rc = cypress_ps2_sendbyte(psmouse, data); + rc = cypress_ps2_sendbyte(psmouse, nibble); if (rc == -EAGAIN) - rc = cypress_ps2_sendbyte(psmouse, data); + rc = cypress_ps2_sendbyte(psmouse, nibble); if (!rc) break; @@ -94,8 +92,7 @@ static int cypress_ps2_ext_cmd(struct psmouse *psmouse, unsigned short cmd, } static int cypress_ps2_read_cmd_status(struct psmouse *psmouse, - unsigned char cmd, - unsigned char *param) + u8 cmd, u8 *param) { struct ps2dev *ps2dev = &psmouse->ps2dev; enum psmouse_state old_state; @@ -111,7 +108,7 @@ static int cypress_ps2_read_cmd_status(struct psmouse *psmouse, pktsize = (cmd == CYTP_CMD_READ_TP_METRICS) ? 8 : 3; memset(param, 0, pktsize); - rc = cypress_ps2_sendbyte(psmouse, 0xe9); + rc = cypress_ps2_sendbyte(psmouse, PSMOUSE_CMD_GETINFO & 0xff); if (rc) goto out; @@ -136,8 +133,7 @@ out: return rc; } -static bool cypress_verify_cmd_state(struct psmouse *psmouse, - unsigned char cmd, unsigned char *param) +static bool cypress_verify_cmd_state(struct psmouse *psmouse, u8 cmd, u8* param) { bool rate_match = false; bool resolution_match = false; @@ -167,31 +163,24 @@ static bool cypress_verify_cmd_state(struct psmouse *psmouse, return false; } -static int cypress_send_ext_cmd(struct psmouse *psmouse, unsigned char cmd, - unsigned char *param) +static int cypress_send_ext_cmd(struct psmouse *psmouse, u8 cmd, u8 *param) { + u8 cmd_prefix = PSMOUSE_CMD_SETRES & 0xff; int tries = CYTP_PS2_CMD_TRIES; - int rc; + int error; psmouse_dbg(psmouse, "send extension cmd 0x%02x, [%d %d %d %d]\n", cmd, DECODE_CMD_AA(cmd), DECODE_CMD_BB(cmd), DECODE_CMD_CC(cmd), DECODE_CMD_DD(cmd)); do { - cypress_ps2_ext_cmd(psmouse, - PSMOUSE_CMD_SETRES, DECODE_CMD_DD(cmd)); - cypress_ps2_ext_cmd(psmouse, - PSMOUSE_CMD_SETRES, DECODE_CMD_CC(cmd)); - cypress_ps2_ext_cmd(psmouse, - PSMOUSE_CMD_SETRES, DECODE_CMD_BB(cmd)); - cypress_ps2_ext_cmd(psmouse, - PSMOUSE_CMD_SETRES, DECODE_CMD_AA(cmd)); - - rc = cypress_ps2_read_cmd_status(psmouse, cmd, param); - if (rc) - continue; - - if (cypress_verify_cmd_state(psmouse, cmd, param)) + cypress_ps2_ext_cmd(psmouse, cmd_prefix, DECODE_CMD_DD(cmd)); + cypress_ps2_ext_cmd(psmouse, cmd_prefix, DECODE_CMD_CC(cmd)); + cypress_ps2_ext_cmd(psmouse, cmd_prefix, DECODE_CMD_BB(cmd)); + cypress_ps2_ext_cmd(psmouse, cmd_prefix, DECODE_CMD_AA(cmd)); + + error = cypress_ps2_read_cmd_status(psmouse, cmd, param); + if (!error && cypress_verify_cmd_state(psmouse, cmd, param)) return 0; } while (--tries > 0); @@ -201,7 +190,7 @@ static int cypress_send_ext_cmd(struct psmouse *psmouse, unsigned char cmd, int cypress_detect(struct psmouse *psmouse, bool set_properties) { - unsigned char param[3]; + u8 param[3]; if (cypress_send_ext_cmd(psmouse, CYTP_CMD_READ_CYPRESS_ID, param)) return -ENODEV; @@ -221,7 +210,7 @@ int cypress_detect(struct psmouse *psmouse, bool set_properties) static int cypress_read_fw_version(struct psmouse *psmouse) { struct cytp_data *cytp = psmouse->private; - unsigned char param[3]; + u8 param[3]; if (cypress_send_ext_cmd(psmouse, CYTP_CMD_READ_CYPRESS_ID, param)) return -ENODEV; @@ -250,7 +239,7 @@ static int cypress_read_fw_version(struct psmouse *psmouse) static int cypress_read_tp_metrics(struct psmouse *psmouse) { struct cytp_data *cytp = psmouse->private; - unsigned char param[8]; + u8 param[8]; /* set default values for tp metrics. */ cytp->tp_width = CYTP_DEFAULT_WIDTH; @@ -338,7 +327,7 @@ static int cypress_query_hardware(struct psmouse *psmouse) static int cypress_set_absolute_mode(struct psmouse *psmouse) { struct cytp_data *cytp = psmouse->private; - unsigned char param[3]; + u8 param[3]; int error; error = cypress_send_ext_cmd(psmouse, CYTP_CMD_ABS_WITH_PRESSURE_MODE, @@ -418,9 +407,9 @@ static int cypress_set_input_params(struct input_dev *input, return 0; } -static int cypress_get_finger_count(unsigned char header_byte) +static int cypress_get_finger_count(u8 header_byte) { - unsigned char bits6_7; + u8 bits6_7; int finger_count; bits6_7 = header_byte >> 6; @@ -445,10 +434,11 @@ static int cypress_get_finger_count(unsigned char header_byte) static int cypress_parse_packet(struct psmouse *psmouse, - struct cytp_data *cytp, struct cytp_report_data *report_data) + struct cytp_data *cytp, + struct cytp_report_data *report_data) { - unsigned char *packet = psmouse->packet; - unsigned char header_byte = packet[0]; + u8 *packet = psmouse->packet; + u8 header_byte = packet[0]; memset(report_data, 0, sizeof(struct cytp_report_data)); @@ -563,7 +553,7 @@ static psmouse_ret_t cypress_validate_byte(struct psmouse *psmouse) { int contact_cnt; int index = psmouse->pktcnt - 1; - unsigned char *packet = psmouse->packet; + u8 *packet = psmouse->packet; struct cytp_data *cytp = psmouse->private; if (index < 0 || index > cytp->pkt_size) -- cgit v1.2.3