* [PATCH 1/2] serial: 8250: Use 'hlist_for_each_entry' to simplify code
@ 2021-04-28 7:30 Christophe JAILLET
2021-04-28 7:30 ` [PATCH 2/2] serial: 8250: Add an empty line and remove some useless {} Christophe JAILLET
2021-04-28 9:05 ` [PATCH 1/2] serial: 8250: Use 'hlist_for_each_entry' to simplify code Andy Shevchenko
0 siblings, 2 replies; 4+ messages in thread
From: Christophe JAILLET @ 2021-04-28 7:30 UTC (permalink / raw)
To: gregkh, jirislaby, lukas, yangyingliang, andriy.shevchenko
Cc: linux-serial, linux-kernel, kernel-janitors, Christophe JAILLET
Use 'hlist_for_each_entry' instead of hand writing it.
This saves a few lines of code.
The comment about warning generated by some gcc version is also removed.
The way 'hlist_for_each_entry' is written should prevent such a warning to
be emitted.
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only
---
drivers/tty/serial/8250/8250_core.c | 18 ++++--------------
1 file changed, 4 insertions(+), 14 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index cae61d1ebec5..081b773a54c9 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -172,7 +172,6 @@ static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
static int serial_link_irq_chain(struct uart_8250_port *up)
{
struct hlist_head *h;
- struct hlist_node *n;
struct irq_info *i;
int ret;
@@ -180,13 +179,11 @@ static int serial_link_irq_chain(struct uart_8250_port *up)
h = &irq_lists[up->port.irq % NR_IRQ_HASH];
- hlist_for_each(n, h) {
- i = hlist_entry(n, struct irq_info, node);
+ hlist_for_each_entry(i, h, node)
if (i->irq == up->port.irq)
break;
- }
- if (n == NULL) {
+ if (i == NULL) {
i = kzalloc(sizeof(struct irq_info), GFP_KERNEL);
if (i == NULL) {
mutex_unlock(&hash_mutex);
@@ -220,25 +217,18 @@ static int serial_link_irq_chain(struct uart_8250_port *up)
static void serial_unlink_irq_chain(struct uart_8250_port *up)
{
- /*
- * yes, some broken gcc emit "warning: 'i' may be used uninitialized"
- * but no, we are not going to take a patch that assigns NULL below.
- */
struct irq_info *i;
- struct hlist_node *n;
struct hlist_head *h;
mutex_lock(&hash_mutex);
h = &irq_lists[up->port.irq % NR_IRQ_HASH];
- hlist_for_each(n, h) {
- i = hlist_entry(n, struct irq_info, node);
+ hlist_for_each_entry(i, h, node)
if (i->irq == up->port.irq)
break;
- }
- BUG_ON(n == NULL);
+ BUG_ON(i == NULL);
BUG_ON(i->head == NULL);
if (list_empty(i->head))
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] serial: 8250: Add an empty line and remove some useless {}
2021-04-28 7:30 [PATCH 1/2] serial: 8250: Use 'hlist_for_each_entry' to simplify code Christophe JAILLET
@ 2021-04-28 7:30 ` Christophe JAILLET
2021-04-28 9:06 ` Andy Shevchenko
2021-04-28 9:05 ` [PATCH 1/2] serial: 8250: Use 'hlist_for_each_entry' to simplify code Andy Shevchenko
1 sibling, 1 reply; 4+ messages in thread
From: Christophe JAILLET @ 2021-04-28 7:30 UTC (permalink / raw)
To: gregkh, jirislaby, lukas, yangyingliang, andriy.shevchenko
Cc: linux-serial, linux-kernel, kernel-janitors, Christophe JAILLET
This fixes the following checkpatch.pl warnings:
WARNING: Missing a blank line after declarations
WARNING: braces {} are not necessary for any arm of this statement
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
drivers/tty/serial/8250/8250_core.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index 081b773a54c9..1082e76c4d37 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -321,9 +321,9 @@ static int univ8250_setup_irq(struct uart_8250_port *up)
* hardware interrupt, we use a timer-based system. The original
* driver used to do this with IRQ0.
*/
- if (!port->irq) {
+ if (!port->irq)
mod_timer(&up->timer, jiffies + uart_poll_timeout(port));
- } else
+ else
retval = serial_link_irq_chain(up);
return retval;
@@ -752,6 +752,7 @@ void serial8250_suspend_port(int line)
if (!console_suspend_enabled && uart_console(port) &&
port->type != PORT_8250) {
unsigned char canary = 0xa5;
+
serial_out(up, UART_SCR, canary);
if (serial_in(up, UART_SCR) == canary)
up->canary = canary;
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] serial: 8250: Use 'hlist_for_each_entry' to simplify code
2021-04-28 7:30 [PATCH 1/2] serial: 8250: Use 'hlist_for_each_entry' to simplify code Christophe JAILLET
2021-04-28 7:30 ` [PATCH 2/2] serial: 8250: Add an empty line and remove some useless {} Christophe JAILLET
@ 2021-04-28 9:05 ` Andy Shevchenko
1 sibling, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2021-04-28 9:05 UTC (permalink / raw)
To: Christophe JAILLET
Cc: gregkh, jirislaby, lukas, yangyingliang, linux-serial,
linux-kernel, kernel-janitors
On Wed, Apr 28, 2021 at 09:30:40AM +0200, Christophe JAILLET wrote:
> Use 'hlist_for_each_entry' instead of hand writing it.
> This saves a few lines of code.
>
> The comment about warning generated by some gcc version is also removed.
> The way 'hlist_for_each_entry' is written should prevent such a warning to
> be emitted.
I checked the implementation of the macros vs. this usage and below seems legit.
However it indeed needs more test coverage because it's sensitive piece of code.
FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
(with the above caveat)
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> Compile tested only
> ---
> drivers/tty/serial/8250/8250_core.c | 18 ++++--------------
> 1 file changed, 4 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
> index cae61d1ebec5..081b773a54c9 100644
> --- a/drivers/tty/serial/8250/8250_core.c
> +++ b/drivers/tty/serial/8250/8250_core.c
> @@ -172,7 +172,6 @@ static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
> static int serial_link_irq_chain(struct uart_8250_port *up)
> {
> struct hlist_head *h;
> - struct hlist_node *n;
> struct irq_info *i;
> int ret;
>
> @@ -180,13 +179,11 @@ static int serial_link_irq_chain(struct uart_8250_port *up)
>
> h = &irq_lists[up->port.irq % NR_IRQ_HASH];
>
> - hlist_for_each(n, h) {
> - i = hlist_entry(n, struct irq_info, node);
> + hlist_for_each_entry(i, h, node)
> if (i->irq == up->port.irq)
> break;
> - }
>
> - if (n == NULL) {
> + if (i == NULL) {
> i = kzalloc(sizeof(struct irq_info), GFP_KERNEL);
> if (i == NULL) {
> mutex_unlock(&hash_mutex);
> @@ -220,25 +217,18 @@ static int serial_link_irq_chain(struct uart_8250_port *up)
>
> static void serial_unlink_irq_chain(struct uart_8250_port *up)
> {
> - /*
> - * yes, some broken gcc emit "warning: 'i' may be used uninitialized"
> - * but no, we are not going to take a patch that assigns NULL below.
> - */
> struct irq_info *i;
> - struct hlist_node *n;
> struct hlist_head *h;
>
> mutex_lock(&hash_mutex);
>
> h = &irq_lists[up->port.irq % NR_IRQ_HASH];
>
> - hlist_for_each(n, h) {
> - i = hlist_entry(n, struct irq_info, node);
> + hlist_for_each_entry(i, h, node)
> if (i->irq == up->port.irq)
> break;
> - }
>
> - BUG_ON(n == NULL);
> + BUG_ON(i == NULL);
> BUG_ON(i->head == NULL);
>
> if (list_empty(i->head))
> --
> 2.30.2
>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] serial: 8250: Add an empty line and remove some useless {}
2021-04-28 7:30 ` [PATCH 2/2] serial: 8250: Add an empty line and remove some useless {} Christophe JAILLET
@ 2021-04-28 9:06 ` Andy Shevchenko
0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2021-04-28 9:06 UTC (permalink / raw)
To: Christophe JAILLET
Cc: gregkh, jirislaby, lukas, yangyingliang, linux-serial,
linux-kernel, kernel-janitors
On Wed, Apr 28, 2021 at 09:30:52AM +0200, Christophe JAILLET wrote:
> This fixes the following checkpatch.pl warnings:
> WARNING: Missing a blank line after declarations
> WARNING: braces {} are not necessary for any arm of this statement
If it makes somebody happier...
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> drivers/tty/serial/8250/8250_core.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
> index 081b773a54c9..1082e76c4d37 100644
> --- a/drivers/tty/serial/8250/8250_core.c
> +++ b/drivers/tty/serial/8250/8250_core.c
> @@ -321,9 +321,9 @@ static int univ8250_setup_irq(struct uart_8250_port *up)
> * hardware interrupt, we use a timer-based system. The original
> * driver used to do this with IRQ0.
> */
> - if (!port->irq) {
> + if (!port->irq)
> mod_timer(&up->timer, jiffies + uart_poll_timeout(port));
> - } else
> + else
> retval = serial_link_irq_chain(up);
>
> return retval;
> @@ -752,6 +752,7 @@ void serial8250_suspend_port(int line)
> if (!console_suspend_enabled && uart_console(port) &&
> port->type != PORT_8250) {
> unsigned char canary = 0xa5;
> +
> serial_out(up, UART_SCR, canary);
> if (serial_in(up, UART_SCR) == canary)
> up->canary = canary;
> --
> 2.30.2
>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-04-28 9:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-28 7:30 [PATCH 1/2] serial: 8250: Use 'hlist_for_each_entry' to simplify code Christophe JAILLET
2021-04-28 7:30 ` [PATCH 2/2] serial: 8250: Add an empty line and remove some useless {} Christophe JAILLET
2021-04-28 9:06 ` Andy Shevchenko
2021-04-28 9:05 ` [PATCH 1/2] serial: 8250: Use 'hlist_for_each_entry' to simplify code Andy Shevchenko
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).