Skip to content

Commit

Permalink
serial: samsung: Neaten dbg uses
Browse files Browse the repository at this point in the history
Add format and argument checking and fix misuses in the dbg macro.

Add __printf
Use %pR for resource
Add #include guard to samsung.h
Move static functions from .h to .c
Use vscnprintf instead of length unguarded vsprintf

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Joe Perches authored and Greg Kroah-Hartman committed May 28, 2014
1 parent 10389e6 commit e4ac92d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
35 changes: 29 additions & 6 deletions drivers/tty/serial/samsung.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@

#include "samsung.h"

#if defined(CONFIG_SERIAL_SAMSUNG_DEBUG) && \
defined(CONFIG_DEBUG_LL) && \
!defined(MODULE)

extern void printascii(const char *);

__printf(1, 2)
static void dbg(const char *fmt, ...)
{
va_list va;
char buff[256];

va_start(va, fmt);
vscnprintf(buff, sizeof(buf), fmt, va);
va_end(va);

printascii(buff);
}

#else
#define dbg(fmt, ...) do { if (0) no_printk(fmt, ##__VA_ARGS__); } while (0)
#endif

/* UART name and device definitions */

#define S3C24XX_SERIAL_NAME "ttySAC"
Expand Down Expand Up @@ -468,8 +491,8 @@ static int s3c24xx_serial_startup(struct uart_port *port)
struct s3c24xx_uart_port *ourport = to_ourport(port);
int ret;

dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
port->mapbase, port->membase);
dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
port, (unsigned long long)port->mapbase, port->membase);

rx_enabled(port) = 1;

Expand Down Expand Up @@ -514,8 +537,8 @@ static int s3c64xx_serial_startup(struct uart_port *port)
struct s3c24xx_uart_port *ourport = to_ourport(port);
int ret;

dbg("s3c64xx_serial_startup: port=%p (%08lx,%p)\n",
port->mapbase, port->membase);
dbg("s3c64xx_serial_startup: port=%p (%08llx,%p)\n",
port, (unsigned long long)port->mapbase, port->membase);

wr_regl(port, S3C64XX_UINTM, 0xf);

Expand Down Expand Up @@ -1160,7 +1183,7 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
return -EINVAL;
}

dbg("resource %p (%lx..%lx)\n", res, res->start, res->end);
dbg("resource %pR)\n", res);

port->membase = devm_ioremap(port->dev, res->start, resource_size(res));
if (!port->membase) {
Expand Down Expand Up @@ -1203,7 +1226,7 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
wr_regl(port, S3C64XX_UINTSP, 0xf);
}

dbg("port: map=%08x, mem=%08x, irq=%d (%d,%d), clock=%ld\n",
dbg("port: map=%08x, mem=%p, irq=%d (%d,%d), clock=%u\n",
port->mapbase, port->membase, port->irq,
ourport->rx_irq, ourport->tx_irq, port->uartclk);

Expand Down
23 changes: 3 additions & 20 deletions drivers/tty/serial/samsung.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef __SAMSUNG_H
#define __SAMSUNG_H

/*
* Driver for Samsung SoC onboard UARTs.
*
Expand Down Expand Up @@ -77,24 +80,4 @@ struct s3c24xx_uart_port {
#define wr_regb(port, reg, val) __raw_writeb(val, portaddr(port, reg))
#define wr_regl(port, reg, val) __raw_writel(val, portaddr(port, reg))

#if defined(CONFIG_SERIAL_SAMSUNG_DEBUG) && \
defined(CONFIG_DEBUG_LL) && \
!defined(MODULE)

extern void printascii(const char *);

static void dbg(const char *fmt, ...)
{
va_list va;
char buff[256];

va_start(va, fmt);
vsprintf(buff, fmt, va);
va_end(va);

printascii(buff);
}

#else
#define dbg(x...) do { } while (0)
#endif

0 comments on commit e4ac92d

Please sign in to comment.