* [PATCH 07/17] tty: ehv_bytecha: use memcpy_and_pad() in local_ev_byte_channel_send()
2023-11-21 9:22 [PATCH 00/17] tty: small cleanups and fixes Jiri Slaby (SUSE)
@ 2023-11-21 9:22 ` Jiri Slaby (SUSE)
2023-11-21 9:22 ` [PATCH 11/17] tty: hvc_console: use flexible array for outbuf Jiri Slaby (SUSE)
2023-11-23 20:19 ` [PATCH 00/17] tty: small cleanups and fixes Greg KH
2 siblings, 0 replies; 5+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-11-21 9:22 UTC (permalink / raw)
To: gregkh
Cc: linuxppc-dev, Jiri Slaby (SUSE), linux-kernel, linux-serial,
Laurentiu Tudor
There is a helper for memcpy(buffer)+memset(the_rest). Use it for
simplicity.
And add a comment why we are doing the copy in the first place.
Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
Cc: linuxppc-dev@lists.ozlabs.org
---
drivers/tty/ehv_bytechan.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/ehv_bytechan.c b/drivers/tty/ehv_bytechan.c
index a067628e01c8..cc9f4338da60 100644
--- a/drivers/tty/ehv_bytechan.c
+++ b/drivers/tty/ehv_bytechan.c
@@ -143,9 +143,12 @@ static unsigned int local_ev_byte_channel_send(unsigned int handle,
char buffer[EV_BYTE_CHANNEL_MAX_BYTES];
unsigned int c = *count;
+ /*
+ * ev_byte_channel_send() expects at least EV_BYTE_CHANNEL_MAX_BYTES
+ * (16 B) in the buffer. Fake it using a local buffer if needed.
+ */
if (c < sizeof(buffer)) {
- memcpy(buffer, p, c);
- memset(&buffer[c], 0, sizeof(buffer) - c);
+ memcpy_and_pad(buffer, sizeof(buffer), p, c, 0);
p = buffer;
}
return ev_byte_channel_send(handle, count, p);
--
2.42.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 11/17] tty: hvc_console: use flexible array for outbuf
2023-11-21 9:22 [PATCH 00/17] tty: small cleanups and fixes Jiri Slaby (SUSE)
2023-11-21 9:22 ` [PATCH 07/17] tty: ehv_bytecha: use memcpy_and_pad() in local_ev_byte_channel_send() Jiri Slaby (SUSE)
@ 2023-11-21 9:22 ` Jiri Slaby (SUSE)
2023-11-23 20:19 ` [PATCH 00/17] tty: small cleanups and fixes Greg KH
2 siblings, 0 replies; 5+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-11-21 9:22 UTC (permalink / raw)
To: gregkh; +Cc: linuxppc-dev, Jiri Slaby (SUSE), linux-kernel, linux-serial
This means:
* move outbuf to the end of struct hvc_struct and convert from pointer
to flexible array (the structure is smaller now)
* use struct_size() at the allocation site
* align outbuf in the struct instead of ALIGN() at kzalloc()
And apart from the above, use u8 instead of char (which are the same
thanks to -funsigned-char). The former is now preferred over the latter.
It makes the code easier to understand.
Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org
---
drivers/tty/hvc/hvc_console.c | 4 +---
drivers/tty/hvc/hvc_console.h | 2 +-
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
index 959fae54ca39..93b613e1f176 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -922,8 +922,7 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
return ERR_PTR(err);
}
- hp = kzalloc(ALIGN(sizeof(*hp), sizeof(long)) + outbuf_size,
- GFP_KERNEL);
+ hp = kzalloc(struct_size(hp, outbuf, outbuf_size), GFP_KERNEL);
if (!hp)
return ERR_PTR(-ENOMEM);
@@ -931,7 +930,6 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
hp->data = data;
hp->ops = ops;
hp->outbuf_size = outbuf_size;
- hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))];
tty_port_init(&hp->port);
hp->port.ops = &hvc_port_ops;
diff --git a/drivers/tty/hvc/hvc_console.h b/drivers/tty/hvc/hvc_console.h
index 9668f821db01..b718714bf399 100644
--- a/drivers/tty/hvc/hvc_console.h
+++ b/drivers/tty/hvc/hvc_console.h
@@ -37,7 +37,6 @@ struct hvc_struct {
spinlock_t lock;
int index;
int do_wakeup;
- char *outbuf;
int outbuf_size;
int n_outbuf;
uint32_t vtermno;
@@ -48,6 +47,7 @@ struct hvc_struct {
struct work_struct tty_resize;
struct list_head next;
unsigned long flags;
+ u8 outbuf[] __aligned(sizeof(long));
};
/* implemented by a low level driver */
--
2.42.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 00/17] tty: small cleanups and fixes
2023-11-21 9:22 [PATCH 00/17] tty: small cleanups and fixes Jiri Slaby (SUSE)
2023-11-21 9:22 ` [PATCH 07/17] tty: ehv_bytecha: use memcpy_and_pad() in local_ev_byte_channel_send() Jiri Slaby (SUSE)
2023-11-21 9:22 ` [PATCH 11/17] tty: hvc_console: use flexible array for outbuf Jiri Slaby (SUSE)
@ 2023-11-23 20:19 ` Greg KH
2023-11-27 9:30 ` Jiri Slaby
2 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2023-11-23 20:19 UTC (permalink / raw)
To: Jiri Slaby (SUSE)
Cc: linux-usb, netdev, linux-alpha, Richard Henderson, linux-kernel,
Eric Dumazet, Ivan Kokshaysky, linux-serial, Jan Kara,
Jakub Kicinski, Matt Turner, Paolo Abeni, linuxppc-dev,
David S. Miller, Laurentiu Tudor
On Tue, Nov 21, 2023 at 10:22:41AM +0100, Jiri Slaby (SUSE) wrote:
> This is a series to fix/clean up some obvious issues I revealed during
> u8+size_t conversions (to be posted later).
I applied most of these except the last few, as I think you were going
to reorder them, right?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 00/17] tty: small cleanups and fixes
2023-11-23 20:19 ` [PATCH 00/17] tty: small cleanups and fixes Greg KH
@ 2023-11-27 9:30 ` Jiri Slaby
0 siblings, 0 replies; 5+ messages in thread
From: Jiri Slaby @ 2023-11-27 9:30 UTC (permalink / raw)
To: Greg KH
Cc: linux-usb, netdev, linux-alpha, Richard Henderson, linux-kernel,
Eric Dumazet, Ivan Kokshaysky, linux-serial, Jan Kara,
Jakub Kicinski, Matt Turner, Paolo Abeni, linuxppc-dev,
David S. Miller, Laurentiu Tudor
On 23. 11. 23, 21:19, Greg KH wrote:
> On Tue, Nov 21, 2023 at 10:22:41AM +0100, Jiri Slaby (SUSE) wrote:
>> This is a series to fix/clean up some obvious issues I revealed during
>> u8+size_t conversions (to be posted later).
>
> I applied most of these except the last few, as I think you were going
> to reorder them, right?
Yes, great. I will rebase and see/resend what is missing.
thanks,
--
js
suse labs
^ permalink raw reply [flat|nested] 5+ messages in thread