All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] tty: serial: msm_serial.c:  Cleaning up uninitialized variables
@ 2014-07-06 16:47 Rickard Strandqvist
  2014-07-09 18:02 ` Stephen Boyd
  0 siblings, 1 reply; 3+ messages in thread
From: Rickard Strandqvist @ 2014-07-06 16:47 UTC (permalink / raw)
  To: David Brown, Daniel Walker
  Cc: Rickard Strandqvist, Bryan Huntsman, Greg Kroah-Hartman,
	Jiri Slaby, Grant Likely, Rob Herring, linux-arm-msm,
	linux-serial, linux-kernel, devicetree

Set reasonable initial value of some variables, in case
they do not get set to something otherwise.
And I've also added a plausibility control of the values.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 drivers/tty/serial/msm_serial.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
index 72000a6..4491108 100644
--- a/drivers/tty/serial/msm_serial.c
+++ b/drivers/tty/serial/msm_serial.c
@@ -917,7 +917,7 @@ static int __init msm_console_setup(struct console *co, char *options)
 {
 	struct uart_port *port;
 	struct msm_port *msm_port;
-	int baud, flow, bits, parity;
+	int baud = 115200, flow = 'n', bits = 8, parity = 'n';
 
 	if (unlikely(co->index >= UART_NR || co->index < 0))
 		return -ENXIO;
@@ -930,17 +930,21 @@ static int __init msm_console_setup(struct console *co, char *options)
 
 	msm_init_clock(port);
 
-	if (options)
+	if (options) {
 		uart_parse_options(options, &baud, &parity, &bits, &flow);
+		if (baud < 300 || baud > 115200)
+			baud = 115200;
+		if (NULL == strchr("noeNOE", parity))
+			parity = 'n';
+		if (bits != 7)
+			bits = 8;
+		if (flow != 'r')
+			flow = 'n';
+	}
 
-	bits = 8;
-	parity = 'n';
-	flow = 'n';
 	msm_write(port, UART_MR2_BITS_PER_CHAR_8 | UART_MR2_STOP_BIT_LEN_ONE,
 		  UART_MR2);	/* 8N1 */
 
-	if (baud < 300 || baud > 115200)
-		baud = 115200;
 	msm_set_baud_rate(port, baud);
 
 	msm_reset(port);
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] tty: serial: msm_serial.c:  Cleaning up uninitialized variables
  2014-07-06 16:47 [PATCH v2] tty: serial: msm_serial.c: Cleaning up uninitialized variables Rickard Strandqvist
@ 2014-07-09 18:02 ` Stephen Boyd
  2014-07-09 21:01   ` Rickard Strandqvist
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Boyd @ 2014-07-09 18:02 UTC (permalink / raw)
  To: Rickard Strandqvist
  Cc: David Brown, Daniel Walker, Bryan Huntsman, Greg Kroah-Hartman,
	Jiri Slaby, Grant Likely, Rob Herring, linux-arm-msm,
	linux-serial, linux-kernel, devicetree

On 07/06/14 09:47, Rickard Strandqvist wrote:
> Set reasonable initial value of some variables, in case
> they do not get set to something otherwise.
> And I've also added a plausibility control of the values.
>
> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
> ---

This patch doesn't look right...

> @@ -930,17 +930,21 @@ static int __init msm_console_setup(struct console *co, char *options)
>  
>  	msm_init_clock(port);
>  
> -	if (options)
> +	if (options) {
>  		uart_parse_options(options, &baud, &parity, &bits, &flow);
> +		if (baud < 300 || baud > 115200)
> +			baud = 115200;
> +		if (NULL == strchr("noeNOE", parity))
> +			parity = 'n';
> +		if (bits != 7)
> +			bits = 8;
> +		if (flow != 'r')
> +			flow = 'n';
> +	}
>  
> -	bits = 8;
> -	parity = 'n';
> -	flow = 'n';
>  	msm_write(port, UART_MR2_BITS_PER_CHAR_8 | UART_MR2_STOP_BIT_LEN_ONE,
>  		  UART_MR2);	/* 8N1 */
>  

because this code is overriding whatever is parsed from
uart_parse_options() on purpose. The hardware is configured for 8 bits,
no parity, no flow control with this msm_write() statement. Maybe we
should extend the code to configure the parity and flow control bits
instead.

> -	if (baud < 300 || baud > 115200)
> -		baud = 115200;
>  	msm_set_baud_rate(port, baud);
>  
>  	msm_reset(port);


-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] tty: serial: msm_serial.c: Cleaning up uninitialized variables
  2014-07-09 18:02 ` Stephen Boyd
@ 2014-07-09 21:01   ` Rickard Strandqvist
  0 siblings, 0 replies; 3+ messages in thread
From: Rickard Strandqvist @ 2014-07-09 21:01 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: David Brown, Daniel Walker, Bryan Huntsman, Greg Kroah-Hartman,
	Jiri Slaby, Grant Likely, Rob Herring, linux-arm-msm,
	linux-serial, linux-kernel, devicetree

2014-07-09 20:02 GMT+02:00 Stephen Boyd <sboyd@codeaurora.org>:
> On 07/06/14 09:47, Rickard Strandqvist wrote:
>> Set reasonable initial value of some variables, in case
>> they do not get set to something otherwise.
>> And I've also added a plausibility control of the values.
>>
>> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
>> ---
>
> This patch doesn't look right...
>
>> @@ -930,17 +930,21 @@ static int __init msm_console_setup(struct console *co, char *options)
>>
>>       msm_init_clock(port);
>>
>> -     if (options)
>> +     if (options) {
>>               uart_parse_options(options, &baud, &parity, &bits, &flow);
>> +             if (baud < 300 || baud > 115200)
>> +                     baud = 115200;
>> +             if (NULL == strchr("noeNOE", parity))
>> +                     parity = 'n';
>> +             if (bits != 7)
>> +                     bits = 8;
>> +             if (flow != 'r')
>> +                     flow = 'n';
>> +     }
>>
>> -     bits = 8;
>> -     parity = 'n';
>> -     flow = 'n';
>>       msm_write(port, UART_MR2_BITS_PER_CHAR_8 | UART_MR2_STOP_BIT_LEN_ONE,
>>                 UART_MR2);    /* 8N1 */
>>
>
> because this code is overriding whatever is parsed from
> uart_parse_options() on purpose. The hardware is configured for 8 bits,
> no parity, no flow control with this msm_write() statement. Maybe we
> should extend the code to configure the parity and flow control bits
> instead.



Hi

Okay, well that explains the strange code.
Maybe there should be a comment about this?

You mean that UART_MR2_BITS_PER_CHAR_8 | UART_MR2_STOP_BIT_LEN_ONE is
set correctly for the msm_write function?
I can do that...

Regardless, the original error whas that baud could be used uninitialized.


Kind regards
Rickard Strandqvist

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-07-09 21:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-06 16:47 [PATCH v2] tty: serial: msm_serial.c: Cleaning up uninitialized variables Rickard Strandqvist
2014-07-09 18:02 ` Stephen Boyd
2014-07-09 21:01   ` Rickard Strandqvist

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.