linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: "Maciej W. Rozycki" <macro@orcam.me.uk>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	johan@kernel.org, "Paul Cercueil" <paul@crapouillou.net>,
	"Tobias Klauser" <tklauser@distanz.ch>,
	"Russell King" <linux@armlinux.org.uk>,
	"Vineet Gupta" <vgupta@kernel.org>,
	"Richard Genoud" <richard.genoud@gmail.com>,
	"Nicolas Ferre" <nicolas.ferre@microchip.com>,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>,
	"Ludovic Desroches" <ludovic.desroches@microchip.com>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Alexander Shiyan" <shc_work@mail.ru>,
	"Baruch Siach" <baruch@tkos.co.il>,
	"Paul Walmsley" <paul.walmsley@sifive.com>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"Albert Ou" <aou@eecs.berkeley.edu>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Fabio Estevam" <festevam@gmail.com>,
	"NXP Linux Team" <linux-imx@nxp.com>,
	"Karol Gugala" <kgugala@antmicro.com>,
	"Mateusz Holenko" <mholenko@antmicro.com>,
	"Vladimir Zapolskiy" <vz@mleia.com>,
	"Neil Armstrong" <narmstrong@baylibre.com>,
	"Kevin Hilman" <khilman@baylibre.com>,
	"Jerome Brunet" <jbrunet@baylibre.com>,
	"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>,
	"Taichi Sugaya" <sugaya.taichi@socionext.com>,
	"Takao Orito" <orito.takao@socionext.com>,
	"Liviu Dudau" <liviu.dudau@arm.com>,
	"Sudeep Holla" <sudeep.holla@arm.com>,
	"Lorenzo Pieralisi" <lorenzo.pieralisi@arm.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"Manivannan Sadhasivam" <mani@kernel.org>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
	"Paul Mackerras" <paulus@samba.org>,
	"Andy Gross" <agross@kernel.org>,
	"Bjorn Andersson" <bjorn.andersson@linaro.org>,
	"Krzysztof Kozlowski" <krzysztof.kozlowski@canonical.com>,
	"Orson Zhai" <orsonzhai@gmail.com>,
	"Baolin Wang" <baolin.wang7@gmail.com>,
	"Chunyan Zhang" <zhang.lyra@gmail.com>,
	"Patrice Chotard" <patrice.chotard@foss.st.com>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Alexandre Torgue" <alexandre.torgue@foss.st.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Peter Korsgaard" <jacmet@sunsite.dk>,
	"Michal Simek" <michal.simek@xilinx.com>
Subject: Re: [PATCH 10/11] serial: make uart_console_write->putchar()'s character a char
Date: Thu, 27 Jan 2022 09:09:28 +0100	[thread overview]
Message-ID: <c5702d8a-d561-31c4-965f-da8953d75ce3@kernel.org> (raw)
In-Reply-To: <alpine.DEB.2.21.2201261700460.58572@angie.orcam.me.uk>

On 26. 01. 22, 18:57, Maciej W. Rozycki wrote:
> On Mon, 24 Jan 2022, Jiri Slaby wrote:
> 
>> diff --git a/drivers/tty/serial/dz.c b/drivers/tty/serial/dz.c
>> index e9edabc5a211..3493e201d67f 100644
>> --- a/drivers/tty/serial/dz.c
>> +++ b/drivers/tty/serial/dz.c
>> @@ -802,7 +802,7 @@ static void __init dz_init_ports(void)
>>    * restored.  Welcome to the world of PDP-11!
>>    * -------------------------------------------------------------------
>>    */
>> -static void dz_console_putchar(struct uart_port *uport, int ch)
>> +static void dz_console_putchar(struct uart_port *uport, char ch)
>>   {
>>   	struct dz_port *dport = to_dport(uport);
>>   	unsigned long flags;
> 
>   Hmm, this is unsafe, because on the MIPS target the lone `char' type is
> signed and therefore a call to `->putchar' will see `ch' sign-extended
> from bit #7 to the width of the argument register used.  Which means that
> if a character is sent to the console that has its bit #7 set, then the
> call to:
> 
> 		dz_out(dport, DZ_TDR, ch);
> 
> i.e.:
> 
> static void dz_out(struct dz_port *dport, unsigned offset, u16 value)
> 
> will send a value to DZ_TDR with bits #15:8 set to all-ones.  And bits
> #11:8 there are the BREAK control bits, active high, for serial lines #3:0
> respectively.
> 
>   We could handle this with a preparatory change by calling:
> 
> 		dz_out(dport, DZ_TDR, ch & 0xffu);
> 
> instead, but perhaps `->putchar' should simply take `unsigned char' or
> maybe even `u8' as its third argument?
> 
>> diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
>> index c58cc142d23f..68e62703eaa6 100644
>> --- a/include/linux/serial_core.h
>> +++ b/include/linux/serial_core.h
>> @@ -399,7 +399,7 @@ int uart_set_options(struct uart_port *port, struct console
>> *co, int baud,
>>   struct tty_driver *uart_console_device(struct console *co, int *index);
>>   void uart_console_write(struct uart_port *port, const char *s,
>>   			unsigned int count,
>> -			void (*putchar)(struct uart_port *, int));
>> +			void (*putchar)(struct uart_port *, char));
>>   
>>   /*
>>    * Port/driver registration/removal
> 
>   I.e.:
> 
> 			void (*putchar)(struct uart_port *, unsigned char));
> 
> I can see we get it right already with:
> 
> 	unsigned char		x_char;			/* xon/xoff char */
> 
> and for `dz_transmit_chars' we have:
> 
> 	unsigned char tmp;
> [...]
> 	tmp = xmit->buf[xmit->tail];
> 	xmit->tail = (xmit->tail + 1) & (DZ_XMIT_SIZE - 1);
> 	dz_out(dport, DZ_TDR, tmp);
> 
> (because `struct circ_buf' is generic and not limited to unsigned buffer
> contents interpretation; it's not clear to me if that has been intended
> though).

Thanks, good point. I was considering unsigned char and concluded not go 
that path right now as the rest of the console world uses char -- 
starting from the printk code. OTOH the whole uart world uses 'unsigned 
char' except that circ_buf. But I am phasing circ_buf out in favor of 
kfifo+unsigned-char anyway.

So let me switch the whole uart (the console code in particular) to an 
unsigned world. Meaning printk will pass char, uart will receive it as 
unsigned char and will keep it unsigned in all cases.

thanks,
-- 
js
suse labs

  reply	other threads:[~2022-01-27  8:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-24  7:14 [PATCH 00/11] TTY patches for 5.18 Jiri Slaby
2022-01-24  7:14 ` [PATCH 01/11] serial: core: clean up EXPORT_SYMBOLs Jiri Slaby
2022-01-24  7:14 ` [PATCH 02/11] serial: atmel_serial: include circ_buf.h Jiri Slaby
2022-01-24  8:46   ` Richard Genoud
2022-01-24  8:49     ` Richard Genoud
2022-01-24  7:14 ` [PATCH 03/11] tty: add kfifo to tty_port Jiri Slaby
2022-01-24  7:14 ` [PATCH 04/11] tty: tty_port_open, document shutdown vs failed activate Jiri Slaby
2022-01-24  7:14 ` [PATCH 05/11] mxser: fix xmit_buf leak in activate when LSR == 0xff Jiri Slaby
2022-01-24  7:14 ` [PATCH 06/11] mxser: use tty_port xmit_buf helpers Jiri Slaby
2022-01-24  7:14 ` [PATCH 07/11] mxser: switch from xmit_buf to kfifo Jiri Slaby
2022-01-24  7:14 ` [PATCH 08/11] serial: fsl_linflexuart: deduplicate character sending Jiri Slaby
2022-01-24  7:14 ` [PATCH 09/11] serial: fsl_linflexuart: don't call uart_write_wakeup() twice Jiri Slaby
2022-01-24  7:14 ` [PATCH 10/11] serial: make uart_console_write->putchar()'s character a char Jiri Slaby
2022-01-24  9:06   ` Richard Genoud
2022-01-24 14:30   ` kernel test robot
2022-01-26  7:26     ` Jiri Slaby
2022-01-26 13:55       ` Greg KH
2022-01-24 16:23   ` kernel test robot
2022-01-26 17:57   ` Maciej W. Rozycki
2022-01-27  8:09     ` Jiri Slaby [this message]
2022-01-24  7:14 ` [PATCH 11/11] serial: mcf: use helpers in mcf_tx_chars() Jiri Slaby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c5702d8a-d561-31c4-965f-da8953d75ce3@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=afaerber@suse.de \
    --cc=agross@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=baolin.wang7@gmail.com \
    --cc=baruch@tkos.co.il \
    --cc=benh@kernel.crashing.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=festevam@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jacmet@sunsite.dk \
    --cc=jbrunet@baylibre.com \
    --cc=johan@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=kgugala@antmicro.com \
    --cc=khilman@baylibre.com \
    --cc=krzysztof.kozlowski@canonical.com \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=liviu.dudau@arm.com \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=ludovic.desroches@microchip.com \
    --cc=macro@orcam.me.uk \
    --cc=mani@kernel.org \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=mholenko@antmicro.com \
    --cc=michal.simek@xilinx.com \
    --cc=mpe@ellerman.id.au \
    --cc=narmstrong@baylibre.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=orito.takao@socionext.com \
    --cc=orsonzhai@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=patrice.chotard@foss.st.com \
    --cc=paul.walmsley@sifive.com \
    --cc=paul@crapouillou.net \
    --cc=paulus@samba.org \
    --cc=richard.genoud@gmail.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=shc_work@mail.ru \
    --cc=sudeep.holla@arm.com \
    --cc=sugaya.taichi@socionext.com \
    --cc=tklauser@distanz.ch \
    --cc=vgupta@kernel.org \
    --cc=vz@mleia.com \
    --cc=zhang.lyra@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).