* [PATCH 0/3] Avoid the use of one-element arrays
@ 2020-07-23 22:30 Gustavo A. R. Silva
2020-07-23 22:31 ` [PATCH 1/3] tty: " Gustavo A. R. Silva
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Gustavo A. R. Silva @ 2020-07-23 22:30 UTC (permalink / raw)
To: linux-kernel; +Cc: Jiri Slaby, Greg Kroah-Hartman, Gustavo A. R. Silva
Hi,
This series aims to:
1. Remove one-element arrays.
2. Fix identation issues in struct serial_struct32
3. Use the preferred form for passing a size of a structure type
Thanks
Gustavo A. R. Silva (3):
tty: Avoid the use of one-element arrays
tty: Fix identation issues in struct serial_struct32
tty: Use the preferred form for passing the size of a structure type
drivers/tty/tty_io.c | 52 ++++++++++++++++++++++----------------------
1 file changed, 26 insertions(+), 26 deletions(-)
--
2.27.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] tty: Avoid the use of one-element arrays
2020-07-23 22:30 [PATCH 0/3] Avoid the use of one-element arrays Gustavo A. R. Silva
@ 2020-07-23 22:31 ` Gustavo A. R. Silva
2020-07-23 22:32 ` [PATCH 2/3] tty: Fix identation issues in struct serial_struct32 Gustavo A. R. Silva
2020-07-23 22:34 ` [PATCH 3/3] tty: Use the preferred form for passing the size of a structure type Gustavo A. R. Silva
2 siblings, 0 replies; 5+ messages in thread
From: Gustavo A. R. Silva @ 2020-07-23 22:31 UTC (permalink / raw)
To: linux-kernel; +Cc: Jiri Slaby, Greg Kroah-Hartman, Gustavo A. R. Silva
One-element arrays are being deprecated[1]. Replace the one-element arrays
with simple value types 'char reserved_char' and 'compat_int_t reserved'[2],
once it seems these are just placeholders for alignment.
[1] https://github.com/KSPP/linux/issues/79
[2] https://github.com/KSPP/linux/issues/86
Tested-by: kernel test robot <lkp@intel.com>
Link: https://github.com/GustavoARSilva/linux-hardening/blob/master/cii/0-day/tty-20200716.md
Acked-by: Jiri Slaby <jirislaby@kernel.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/tty/tty_io.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 5a6f36b391d9..3b6e5ec3ba54 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2683,7 +2683,7 @@ struct serial_struct32 {
compat_int_t baud_base;
unsigned short close_delay;
char io_type;
- char reserved_char[1];
+ char reserved_char;
compat_int_t hub6;
unsigned short closing_wait; /* time to wait before closing */
unsigned short closing_wait2; /* no longer used... */
@@ -2691,7 +2691,7 @@ struct serial_struct32 {
unsigned short iomem_reg_shift;
unsigned int port_high;
/* compat_ulong_t iomap_base FIXME */
- compat_int_t reserved[1];
+ compat_int_t reserved;
};
static int compat_tty_tiocsserial(struct tty_struct *tty,
--
2.27.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] tty: Fix identation issues in struct serial_struct32
2020-07-23 22:30 [PATCH 0/3] Avoid the use of one-element arrays Gustavo A. R. Silva
2020-07-23 22:31 ` [PATCH 1/3] tty: " Gustavo A. R. Silva
@ 2020-07-23 22:32 ` Gustavo A. R. Silva
2020-07-23 22:34 ` [PATCH 3/3] tty: Use the preferred form for passing the size of a structure type Gustavo A. R. Silva
2 siblings, 0 replies; 5+ messages in thread
From: Gustavo A. R. Silva @ 2020-07-23 22:32 UTC (permalink / raw)
To: linux-kernel; +Cc: Jiri Slaby, Greg Kroah-Hartman, Gustavo A. R. Silva
Fix the following checkpatch.pl warnings together with all the
identation issues in struct serial_struct32:
ERROR: code indent should use tabs where possible
+ char reserved_char;$
WARNING: please, no spaces at the start of a line
+ char reserved_char;$
ERROR: code indent should use tabs where possible
+ compat_int_t reserved;$
WARNING: please, no spaces at the start of a line
+ compat_int_t reserved;$
Acked-by: Jiri Slaby <jirislaby@kernel.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/tty/tty_io.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 3b6e5ec3ba54..629fbafc9b7e 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2673,25 +2673,25 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
#ifdef CONFIG_COMPAT
struct serial_struct32 {
- compat_int_t type;
- compat_int_t line;
- compat_uint_t port;
- compat_int_t irq;
- compat_int_t flags;
- compat_int_t xmit_fifo_size;
- compat_int_t custom_divisor;
- compat_int_t baud_base;
- unsigned short close_delay;
- char io_type;
- char reserved_char;
- compat_int_t hub6;
- unsigned short closing_wait; /* time to wait before closing */
- unsigned short closing_wait2; /* no longer used... */
- compat_uint_t iomem_base;
- unsigned short iomem_reg_shift;
- unsigned int port_high;
- /* compat_ulong_t iomap_base FIXME */
- compat_int_t reserved;
+ compat_int_t type;
+ compat_int_t line;
+ compat_uint_t port;
+ compat_int_t irq;
+ compat_int_t flags;
+ compat_int_t xmit_fifo_size;
+ compat_int_t custom_divisor;
+ compat_int_t baud_base;
+ unsigned short close_delay;
+ char io_type;
+ char reserved_char;
+ compat_int_t hub6;
+ unsigned short closing_wait; /* time to wait before closing */
+ unsigned short closing_wait2; /* no longer used... */
+ compat_uint_t iomem_base;
+ unsigned short iomem_reg_shift;
+ unsigned int port_high;
+ /* compat_ulong_t iomap_base FIXME */
+ compat_int_t reserved;
};
static int compat_tty_tiocsserial(struct tty_struct *tty,
--
2.27.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] tty: Use the preferred form for passing the size of a structure type
2020-07-23 22:30 [PATCH 0/3] Avoid the use of one-element arrays Gustavo A. R. Silva
2020-07-23 22:31 ` [PATCH 1/3] tty: " Gustavo A. R. Silva
2020-07-23 22:32 ` [PATCH 2/3] tty: Fix identation issues in struct serial_struct32 Gustavo A. R. Silva
@ 2020-07-23 22:34 ` Gustavo A. R. Silva
2020-07-29 7:55 ` Jiri Slaby
2 siblings, 1 reply; 5+ messages in thread
From: Gustavo A. R. Silva @ 2020-07-23 22:34 UTC (permalink / raw)
To: linux-kernel; +Cc: Jiri Slaby, Greg Kroah-Hartman, Gustavo A. R. Silva
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 <gustavoars@kernel.org>
---
drivers/tty/tty_io.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 629fbafc9b7e..ceed72c9a88f 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1405,7 +1405,7 @@ void tty_save_termios(struct tty_struct *tty)
/* Stash the termios data */
tp = tty->driver->termios[idx];
if (tp == NULL) {
- tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
+ tp = kmalloc(sizeof(*tp), GFP_KERNEL);
if (tp == NULL)
return;
tty->driver->termios[idx] = tp;
@@ -2489,7 +2489,7 @@ static int tty_tiocsserial(struct tty_struct *tty, struct serial_struct __user *
struct serial_struct v;
int flags;
- if (copy_from_user(&v, ss, sizeof(struct serial_struct)))
+ if (copy_from_user(&v, ss, sizeof(*ss)))
return -EFAULT;
flags = v.flags & ASYNC_DEPRECATED;
@@ -2507,11 +2507,11 @@ static int tty_tiocgserial(struct tty_struct *tty, struct serial_struct __user *
struct serial_struct v;
int err;
- memset(&v, 0, sizeof(struct serial_struct));
+ memset(&v, 0, sizeof(v));
if (!tty->ops->get_serial)
return -ENOTTY;
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;
return err;
}
@@ -2705,7 +2705,7 @@ static int compat_tty_tiocsserial(struct tty_struct *tty,
struct serial_struct v;
int flags;
- if (copy_from_user(&v32, ss, sizeof(struct serial_struct32)))
+ if (copy_from_user(&v32, ss, sizeof(*ss)))
return -EFAULT;
memcpy(&v, &v32, offsetof(struct serial_struct32, iomem_base));
@@ -2743,7 +2743,7 @@ static int compat_tty_tiocgserial(struct tty_struct *tty,
0xfffffff : ptr_to_compat(v.iomem_base);
v32.iomem_reg_shift = v.iomem_reg_shift;
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;
}
return err;
@@ -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))
return ERR_PTR(-EINVAL);
- driver = kzalloc(sizeof(struct tty_driver), GFP_KERNEL);
+ driver = kzalloc(sizeof(*driver), GFP_KERNEL);
if (!driver)
return ERR_PTR(-ENOMEM);
--
2.27.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 3/3] tty: Use the preferred form for passing the size of a structure type
2020-07-23 22:34 ` [PATCH 3/3] tty: Use the preferred form for passing the size of a structure type Gustavo A. R. Silva
@ 2020-07-29 7:55 ` Jiri Slaby
0 siblings, 0 replies; 5+ messages in thread
From: Jiri Slaby @ 2020-07-29 7:55 UTC (permalink / raw)
To: Gustavo A. R. Silva, linux-kernel; +Cc: Greg Kroah-Hartman
On 24. 07. 20, 0:34, Gustavo A. R. Silva wrote:
> 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 <gustavoars@kernel.org>
Acked-by: Jiri Slaby <jirislaby@kernel.org>
The other 2 ones are already acked by me.
thanks,
--
js
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-07-29 7:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-23 22:30 [PATCH 0/3] Avoid the use of one-element arrays Gustavo A. R. Silva
2020-07-23 22:31 ` [PATCH 1/3] tty: " Gustavo A. R. Silva
2020-07-23 22:32 ` [PATCH 2/3] tty: Fix identation issues in struct serial_struct32 Gustavo A. R. Silva
2020-07-23 22:34 ` [PATCH 3/3] tty: Use the preferred form for passing the size of a structure type Gustavo A. R. Silva
2020-07-29 7:55 ` Jiri Slaby
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).