Input: touchscreen - use sizeof(*pointer) instead of sizeof(type)
authorErick Archer <erick.archer@outlook.com>
Sat, 8 Jun 2024 14:34:49 +0000 (16:34 +0200)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Sun, 9 Jun 2024 21:38:38 +0000 (14:38 -0700)
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).

The refactoring is mostly trivial except for "usbtouchscreen.c"
file. Here, in the "mtouch_alloc" and "nexio_alloc" functions,
it is necessary to use a variable with a predefined type instead
of the "usbtouch->priv" variable (void * type). This way, the
"sizeof" operator can now know the correct size. Moreover, we
need to set the "usbtouch->priv" pointer after the memory
allocation since now the "kmalloc" return value is not assigned
directly.

This patch has no effect on runtime behavior.

Signed-off-by: Erick Archer <erick.archer@outlook.com>
Link: https://lore.kernel.org/r/AS8PR02MB723708364CC0DF2EAAFEE5968BC42@AS8PR02MB7237.eurprd02.prod.outlook.com
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
17 files changed:
drivers/input/touchscreen/da9052_tsi.c
drivers/input/touchscreen/dynapro.c
drivers/input/touchscreen/egalax_ts_serial.c
drivers/input/touchscreen/elo.c
drivers/input/touchscreen/fujitsu_ts.c
drivers/input/touchscreen/gunze.c
drivers/input/touchscreen/hampshire.c
drivers/input/touchscreen/inexio.c
drivers/input/touchscreen/mtouch.c
drivers/input/touchscreen/penmount.c
drivers/input/touchscreen/sur40.c
drivers/input/touchscreen/touchit213.c
drivers/input/touchscreen/touchright.c
drivers/input/touchscreen/touchwin.c
drivers/input/touchscreen/tsc40.c
drivers/input/touchscreen/usbtouchscreen.c
drivers/input/touchscreen/wacom_w8001.c

index d71690c..52e0e83 100644 (file)
@@ -232,7 +232,7 @@ static int da9052_ts_probe(struct platform_device *pdev)
        if (!da9052)
                return -EINVAL;
 
-       tsi = kzalloc(sizeof(struct da9052_tsi), GFP_KERNEL);
+       tsi = kzalloc(sizeof(*tsi), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!tsi || !input_dev) {
                error = -ENOMEM;
index dc07fca..fe626a2 100644 (file)
@@ -110,7 +110,7 @@ static int dynapro_connect(struct serio *serio, struct serio_driver *drv)
        struct input_dev *input_dev;
        int err;
 
-       pdynapro = kzalloc(sizeof(struct dynapro), GFP_KERNEL);
+       pdynapro = kzalloc(sizeof(*pdynapro), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!pdynapro || !input_dev) {
                err = -ENOMEM;
index 375922d..07a4aa1 100644 (file)
@@ -99,7 +99,7 @@ static int egalax_connect(struct serio *serio, struct serio_driver *drv)
        struct input_dev *input_dev;
        int error;
 
-       egalax = kzalloc(sizeof(struct egalax), GFP_KERNEL);
+       egalax = kzalloc(sizeof(*egalax), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!egalax || !input_dev) {
                error = -ENOMEM;
index 9617323..eb883db 100644 (file)
@@ -307,7 +307,7 @@ static int elo_connect(struct serio *serio, struct serio_driver *drv)
        struct input_dev *input_dev;
        int err;
 
-       elo = kzalloc(sizeof(struct elo), GFP_KERNEL);
+       elo = kzalloc(sizeof(*elo), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!elo || !input_dev) {
                err = -ENOMEM;
index 3b0b8fc..1a3e14e 100644 (file)
@@ -99,7 +99,7 @@ static int fujitsu_connect(struct serio *serio, struct serio_driver *drv)
        struct input_dev *input_dev;
        int err;
 
-       fujitsu = kzalloc(sizeof(struct fujitsu), GFP_KERNEL);
+       fujitsu = kzalloc(sizeof(*fujitsu), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!fujitsu || !input_dev) {
                err = -ENOMEM;
index 5a5f9da..dbf92fb 100644 (file)
@@ -97,7 +97,7 @@ static int gunze_connect(struct serio *serio, struct serio_driver *drv)
        struct input_dev *input_dev;
        int err;
 
-       gunze = kzalloc(sizeof(struct gunze), GFP_KERNEL);
+       gunze = kzalloc(sizeof(*gunze), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!gunze || !input_dev) {
                err = -ENOMEM;
index 5c4d877..dc0a248 100644 (file)
@@ -109,7 +109,7 @@ static int hampshire_connect(struct serio *serio, struct serio_driver *drv)
        struct input_dev *input_dev;
        int err;
 
-       phampshire = kzalloc(sizeof(struct hampshire), GFP_KERNEL);
+       phampshire = kzalloc(sizeof(*phampshire), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!phampshire || !input_dev) {
                err = -ENOMEM;
index 1d7e4c3..82f7ac6 100644 (file)
@@ -114,7 +114,7 @@ static int inexio_connect(struct serio *serio, struct serio_driver *drv)
        struct input_dev *input_dev;
        int err;
 
-       pinexio = kzalloc(sizeof(struct inexio), GFP_KERNEL);
+       pinexio = kzalloc(sizeof(*pinexio), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!pinexio || !input_dev) {
                err = -ENOMEM;
index 28e449e..eefae96 100644 (file)
@@ -128,7 +128,7 @@ static int mtouch_connect(struct serio *serio, struct serio_driver *drv)
        struct input_dev *input_dev;
        int err;
 
-       mtouch = kzalloc(sizeof(struct mtouch), GFP_KERNEL);
+       mtouch = kzalloc(sizeof(*mtouch), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!mtouch || !input_dev) {
                err = -ENOMEM;
index 12abb3b..95adede 100644 (file)
@@ -199,7 +199,7 @@ static int pm_connect(struct serio *serio, struct serio_driver *drv)
        int max_x, max_y;
        int err;
 
-       pm = kzalloc(sizeof(struct pm), GFP_KERNEL);
+       pm = kzalloc(sizeof(*pm), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!pm || !input_dev) {
                err = -ENOMEM;
index 5f2cf88..8365a2a 100644 (file)
@@ -672,7 +672,7 @@ static int sur40_probe(struct usb_interface *interface,
                return -ENODEV;
 
        /* Allocate memory for our device state and initialize it. */
-       sur40 = kzalloc(sizeof(struct sur40_state), GFP_KERNEL);
+       sur40 = kzalloc(sizeof(*sur40), GFP_KERNEL);
        if (!sur40)
                return -ENOMEM;
 
index fb49687..c271835 100644 (file)
@@ -139,7 +139,7 @@ static int touchit213_connect(struct serio *serio, struct serio_driver *drv)
        struct input_dev *input_dev;
        int err;
 
-       touchit213 = kzalloc(sizeof(struct touchit213), GFP_KERNEL);
+       touchit213 = kzalloc(sizeof(*touchit213), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!touchit213 || !input_dev) {
                err = -ENOMEM;
index 3cd58a1..30ba97b 100644 (file)
@@ -102,7 +102,7 @@ static int tr_connect(struct serio *serio, struct serio_driver *drv)
        struct input_dev *input_dev;
        int err;
 
-       tr = kzalloc(sizeof(struct tr), GFP_KERNEL);
+       tr = kzalloc(sizeof(*tr), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!tr || !input_dev) {
                err = -ENOMEM;
index bde3c6e..fbd7278 100644 (file)
@@ -109,7 +109,7 @@ static int tw_connect(struct serio *serio, struct serio_driver *drv)
        struct input_dev *input_dev;
        int err;
 
-       tw = kzalloc(sizeof(struct tw), GFP_KERNEL);
+       tw = kzalloc(sizeof(*tw), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!tw || !input_dev) {
                err = -ENOMEM;
index 1395770..9f485cf 100644 (file)
@@ -83,7 +83,7 @@ static int tsc_connect(struct serio *serio, struct serio_driver *drv)
        struct input_dev *input_dev;
        int error;
 
-       ptsc = kzalloc(sizeof(struct tsc_ser), GFP_KERNEL);
+       ptsc = kzalloc(sizeof(*ptsc), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!ptsc || !input_dev) {
                error = -ENOMEM;
index 60354eb..dd6b12c 100644 (file)
@@ -505,12 +505,14 @@ free:
 
 static int mtouch_alloc(struct usbtouch_usb *usbtouch)
 {
+       struct mtouch_priv *priv;
        int ret;
 
-       usbtouch->priv = kmalloc(sizeof(struct mtouch_priv), GFP_KERNEL);
-       if (!usbtouch->priv)
+       priv = kmalloc(sizeof(*priv), GFP_KERNEL);
+       if (!priv)
                return -ENOMEM;
 
+       usbtouch->priv = priv;
        ret = sysfs_create_group(&usbtouch->interface->dev.kobj,
                                 &mtouch_attr_group);
        if (ret) {
@@ -924,12 +926,11 @@ static int nexio_alloc(struct usbtouch_usb *usbtouch)
        struct nexio_priv *priv;
        int ret = -ENOMEM;
 
-       usbtouch->priv = kmalloc(sizeof(struct nexio_priv), GFP_KERNEL);
-       if (!usbtouch->priv)
+       priv = kmalloc(sizeof(*priv), GFP_KERNEL);
+       if (!priv)
                goto out_buf;
 
-       priv = usbtouch->priv;
-
+       usbtouch->priv = priv;
        priv->ack_buf = kmemdup(nexio_ack_pkt, sizeof(nexio_ack_pkt),
                                GFP_KERNEL);
        if (!priv->ack_buf)
@@ -1661,7 +1662,7 @@ static int usbtouch_probe(struct usb_interface *intf,
        if (!endpoint)
                return -ENXIO;
 
-       usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
+       usbtouch = kzalloc(sizeof(*usbtouch), GFP_KERNEL);
        input_dev = input_allocate_device();
        if (!usbtouch || !input_dev)
                goto out_free;
index 4ddb6b3..c8abb95 100644 (file)
@@ -598,7 +598,7 @@ static int w8001_connect(struct serio *serio, struct serio_driver *drv)
        char basename[64] = "Wacom Serial";
        int err, err_pen, err_touch;
 
-       w8001 = kzalloc(sizeof(struct w8001), GFP_KERNEL);
+       w8001 = kzalloc(sizeof(*w8001), GFP_KERNEL);
        input_dev_pen = input_allocate_device();
        input_dev_touch = input_allocate_device();
        if (!w8001 || !input_dev_pen || !input_dev_touch) {