From patchwork Sat Feb 23 13:02:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 222730 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 5E3A32C029B for ; Sun, 24 Feb 2013 00:14:36 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758936Ab3BWNOd (ORCPT ); Sat, 23 Feb 2013 08:14:33 -0500 Received: from forward4h.mail.yandex.net ([84.201.186.22]:53181 "EHLO forward4h.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756179Ab3BWNOc (ORCPT ); Sat, 23 Feb 2013 08:14:32 -0500 X-Greylist: delayed 694 seconds by postgrey-1.27 at vger.kernel.org; Sat, 23 Feb 2013 08:14:32 EST Received: from web1h.yandex.ru (web1h.yandex.ru [84.201.186.30]) by forward4h.mail.yandex.net (Yandex) with ESMTP id 1FF7D1B219C9; Sat, 23 Feb 2013 17:02:55 +0400 (MSK) Received: from 127.0.0.1 (localhost.localdomain [127.0.0.1]) by web1h.yandex.ru (Yandex) with ESMTP id 92FC7A08034; Sat, 23 Feb 2013 17:02:54 +0400 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1361624574; bh=/B4XXvlrl84qKmY/a3WUr9ZO2IIamU61Xf+Y5085vhI=; h=From:To:Cc:Subject:Date; b=RkncEwEYwFuTEA1CeWMsmhldyj/TWrbc1v3WcFo1PRcAq84yRHvh1T/q2bXJdu3VQ ywqMhLtcDCAA9+0LGg+BwoObq2+9kC8hynWvV5GwAcKwFkBwPlDv4jxrWtXCJWVFHc G1RZhHYgQleuwY9ijPZpxUfAAPvueMF+VeImSfTE= Received: from host-77-41-121-97.qwerty.ru (host-77-41-121-97.qwerty.ru [77.41.121.97]) by web1h.yandex.ru with HTTP; Sat, 23 Feb 2013 17:02:54 +0400 From: Kirill Tkhai To: "sparclinux@vger.kernel.org" Cc: David Miller Subject: Panic at sunsu driver MIME-Version: 1.0 Message-Id: <254051361624574@web1h.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Sat, 23 Feb 2013 17:02:54 +0400 Sender: sparclinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: sparclinux@vger.kernel.org Hi! I played with sparc64 kernel on QEMU. It creates single sunsu port and cmdline "console=ttyS1" leads to kernel panic. Unable to handle kernel NULL pointer dereference TPC: RPC: I7: Call Trace: [0000000000453a38] register_console+0x378/0x3e0 [0000000000576fa0] uart_add_one_port+0x2e0/0x340 [000000000057af40] su_probe+0x160/0x2e0 [00000000005b8a4c] platform_drv_probe+0xc/0x20 [00000000005b6c2c] driver_probe_device+0x12c/0x220 [00000000005b6da8] __driver_attach+0x88/0xa0 [00000000005b4df4] bus_for_each_dev+0x54/0xa0 [00000000005b5a54] bus_add_driver+0x154/0x260 [00000000005b7190] driver_register+0x50/0x180 [00000000006d250c] sunsu_init+0x18c/0x1e0 [00000000006c2668] do_one_initcall+0xe8/0x160 [00000000006c282c] kernel_init_freeable+0x12c/0x1e0 [0000000000603764] kernel_init+0x4/0x100 [0000000000405f64] ret_from_syscall+0x1c/0x2c [0000000000000000] (null) I fixed sunsu driver a little bit to prevet this. 1)Is real hardware able to have less than 4 ports? 2)If a machine has 4 ports we'll still skip "console=ttyS1" because it's not registered at the time of the first call of sunsu_console_setup(the first call is with index==1), right? Kirill --- drivers/tty/serial/sunsu.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe sparclinux" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/tty/serial/sunsu.c b/drivers/tty/serial/sunsu.c index e343d66..451687c 100644 --- a/drivers/tty/serial/sunsu.c +++ b/drivers/tty/serial/sunsu.c @@ -968,6 +968,7 @@ static struct uart_ops sunsu_pops = { #define UART_NR 4 static struct uart_sunsu_port sunsu_ports[UART_NR]; +static int nr_inst; /* Number of already registered ports */ #ifdef CONFIG_SERIO @@ -1337,13 +1338,8 @@ static int __init sunsu_console_setup(struct console *co, char *options) printk("Console: ttyS%d (SU)\n", (sunsu_reg.minor - 64) + co->index); - /* - * Check whether an invalid uart number has been specified, and - * if so, search for the first available port that does have - * console support. - */ - if (co->index >= UART_NR) - co->index = 0; + if (co->index > nr_inst) + return -ENODEV; port = &sunsu_ports[co->index].port; /* @@ -1408,7 +1404,6 @@ static enum su_type su_get_type(struct device_node *dp) static int su_probe(struct platform_device *op) { - static int inst; struct device_node *dp = op->dev.of_node; struct uart_sunsu_port *up; struct resource *rp; @@ -1418,16 +1413,16 @@ static int su_probe(struct platform_device *op) type = su_get_type(dp); if (type == SU_PORT_PORT) { - if (inst >= UART_NR) + if (nr_inst >= UART_NR) return -EINVAL; - up = &sunsu_ports[inst]; + up = &sunsu_ports[nr_inst]; } else { up = kzalloc(sizeof(*up), GFP_KERNEL); if (!up) return -ENOMEM; } - up->port.line = inst; + up->port.line = nr_inst; spin_lock_init(&up->port.lock); @@ -1461,6 +1456,8 @@ static int su_probe(struct platform_device *op) } dev_set_drvdata(&op->dev, up); + nr_inst++; + return 0; } @@ -1488,7 +1485,7 @@ static int su_probe(struct platform_device *op) dev_set_drvdata(&op->dev, up); - inst++; + nr_inst++; return 0;