Skip to content

Commit a324189

Browse files
GustavoARSilvagregkh
authored andcommitted
tty: Use the preferred form for passing the size of a structure type
Use the preferred form for passing the size of a structure type. The alternative form where the structure type is spelled out hurts readability and introduces an opportunity for a bug when the object type is changed but the corresponding object identifier to which the sizeof operator is applied is not. Signed-off-by: Gustavo A. R. Silva <[email protected]> Acked-by: Jiri Slaby <[email protected]> Link: https://lore.kernel.org/r/b04dd8cdd67bd6ffde3fd12940aeef35fdb824a6.1595543280.git.gustavoars@kernel.org Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 52b52e9 commit a324189

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/tty/tty_io.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ void tty_save_termios(struct tty_struct *tty)
14051405
/* Stash the termios data */
14061406
tp = tty->driver->termios[idx];
14071407
if (tp == NULL) {
1408-
tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
1408+
tp = kmalloc(sizeof(*tp), GFP_KERNEL);
14091409
if (tp == NULL)
14101410
return;
14111411
tty->driver->termios[idx] = tp;
@@ -2489,7 +2489,7 @@ static int tty_tiocsserial(struct tty_struct *tty, struct serial_struct __user *
24892489
struct serial_struct v;
24902490
int flags;
24912491

2492-
if (copy_from_user(&v, ss, sizeof(struct serial_struct)))
2492+
if (copy_from_user(&v, ss, sizeof(*ss)))
24932493
return -EFAULT;
24942494

24952495
flags = v.flags & ASYNC_DEPRECATED;
@@ -2507,11 +2507,11 @@ static int tty_tiocgserial(struct tty_struct *tty, struct serial_struct __user *
25072507
struct serial_struct v;
25082508
int err;
25092509

2510-
memset(&v, 0, sizeof(struct serial_struct));
2510+
memset(&v, 0, sizeof(v));
25112511
if (!tty->ops->get_serial)
25122512
return -ENOTTY;
25132513
err = tty->ops->get_serial(tty, &v);
2514-
if (!err && copy_to_user(ss, &v, sizeof(struct serial_struct)))
2514+
if (!err && copy_to_user(ss, &v, sizeof(v)))
25152515
err = -EFAULT;
25162516
return err;
25172517
}
@@ -2705,7 +2705,7 @@ static int compat_tty_tiocsserial(struct tty_struct *tty,
27052705
struct serial_struct v;
27062706
int flags;
27072707

2708-
if (copy_from_user(&v32, ss, sizeof(struct serial_struct32)))
2708+
if (copy_from_user(&v32, ss, sizeof(*ss)))
27092709
return -EFAULT;
27102710

27112711
memcpy(&v, &v32, offsetof(struct serial_struct32, iomem_base));
@@ -2743,7 +2743,7 @@ static int compat_tty_tiocgserial(struct tty_struct *tty,
27432743
0xfffffff : ptr_to_compat(v.iomem_base);
27442744
v32.iomem_reg_shift = v.iomem_reg_shift;
27452745
v32.port_high = v.port_high;
2746-
if (copy_to_user(ss, &v32, sizeof(struct serial_struct32)))
2746+
if (copy_to_user(ss, &v32, sizeof(v32)))
27472747
err = -EFAULT;
27482748
}
27492749
return err;
@@ -3215,7 +3215,7 @@ struct tty_driver *__tty_alloc_driver(unsigned int lines, struct module *owner,
32153215
if (!lines || (flags & TTY_DRIVER_UNNUMBERED_NODE && lines > 1))
32163216
return ERR_PTR(-EINVAL);
32173217

3218-
driver = kzalloc(sizeof(struct tty_driver), GFP_KERNEL);
3218+
driver = kzalloc(sizeof(*driver), GFP_KERNEL);
32193219
if (!driver)
32203220
return ERR_PTR(-ENOMEM);
32213221

0 commit comments

Comments
 (0)