Commit a3241891 authored by Gustavo A. R. Silva's avatar Gustavo A. R. Silva Committed by Greg Kroah-Hartman

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: default avatarGustavo A. R. Silva <gustavoars@kernel.org>
Acked-by: default avatarJiri Slaby <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/b04dd8cdd67bd6ffde3fd12940aeef35fdb824a6.1595543280.git.gustavoars@kernel.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 52b52e91
...@@ -1405,7 +1405,7 @@ void tty_save_termios(struct tty_struct *tty) ...@@ -1405,7 +1405,7 @@ void tty_save_termios(struct tty_struct *tty)
/* Stash the termios data */ /* Stash the termios data */
tp = tty->driver->termios[idx]; tp = tty->driver->termios[idx];
if (tp == NULL) { if (tp == NULL) {
tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL); tp = kmalloc(sizeof(*tp), GFP_KERNEL);
if (tp == NULL) if (tp == NULL)
return; return;
tty->driver->termios[idx] = tp; tty->driver->termios[idx] = tp;
...@@ -2489,7 +2489,7 @@ static int tty_tiocsserial(struct tty_struct *tty, struct serial_struct __user * ...@@ -2489,7 +2489,7 @@ static int tty_tiocsserial(struct tty_struct *tty, struct serial_struct __user *
struct serial_struct v; struct serial_struct v;
int flags; int flags;
if (copy_from_user(&v, ss, sizeof(struct serial_struct))) if (copy_from_user(&v, ss, sizeof(*ss)))
return -EFAULT; return -EFAULT;
flags = v.flags & ASYNC_DEPRECATED; flags = v.flags & ASYNC_DEPRECATED;
...@@ -2507,11 +2507,11 @@ static int tty_tiocgserial(struct tty_struct *tty, struct serial_struct __user * ...@@ -2507,11 +2507,11 @@ static int tty_tiocgserial(struct tty_struct *tty, struct serial_struct __user *
struct serial_struct v; struct serial_struct v;
int err; int err;
memset(&v, 0, sizeof(struct serial_struct)); memset(&v, 0, sizeof(v));
if (!tty->ops->get_serial) if (!tty->ops->get_serial)
return -ENOTTY; return -ENOTTY;
err = tty->ops->get_serial(tty, &v); err = tty->ops->get_serial(tty, &v);
if (!err && copy_to_user(ss, &v, sizeof(struct serial_struct))) if (!err && copy_to_user(ss, &v, sizeof(v)))
err = -EFAULT; err = -EFAULT;
return err; return err;
} }
...@@ -2705,7 +2705,7 @@ static int compat_tty_tiocsserial(struct tty_struct *tty, ...@@ -2705,7 +2705,7 @@ static int compat_tty_tiocsserial(struct tty_struct *tty,
struct serial_struct v; struct serial_struct v;
int flags; int flags;
if (copy_from_user(&v32, ss, sizeof(struct serial_struct32))) if (copy_from_user(&v32, ss, sizeof(*ss)))
return -EFAULT; return -EFAULT;
memcpy(&v, &v32, offsetof(struct serial_struct32, iomem_base)); memcpy(&v, &v32, offsetof(struct serial_struct32, iomem_base));
...@@ -2743,7 +2743,7 @@ static int compat_tty_tiocgserial(struct tty_struct *tty, ...@@ -2743,7 +2743,7 @@ static int compat_tty_tiocgserial(struct tty_struct *tty,
0xfffffff : ptr_to_compat(v.iomem_base); 0xfffffff : ptr_to_compat(v.iomem_base);
v32.iomem_reg_shift = v.iomem_reg_shift; v32.iomem_reg_shift = v.iomem_reg_shift;
v32.port_high = v.port_high; v32.port_high = v.port_high;
if (copy_to_user(ss, &v32, sizeof(struct serial_struct32))) if (copy_to_user(ss, &v32, sizeof(v32)))
err = -EFAULT; err = -EFAULT;
} }
return err; return err;
...@@ -3215,7 +3215,7 @@ struct tty_driver *__tty_alloc_driver(unsigned int lines, struct module *owner, ...@@ -3215,7 +3215,7 @@ struct tty_driver *__tty_alloc_driver(unsigned int lines, struct module *owner,
if (!lines || (flags & TTY_DRIVER_UNNUMBERED_NODE && lines > 1)) if (!lines || (flags & TTY_DRIVER_UNNUMBERED_NODE && lines > 1))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
driver = kzalloc(sizeof(struct tty_driver), GFP_KERNEL); driver = kzalloc(sizeof(*driver), GFP_KERNEL);
if (!driver) if (!driver)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment