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>
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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) {
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)
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;
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) {