From: Mark Hounschell <markh@compro.net>
To: driverdev-devel@linuxdriverproject.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH] staging: dgap: fix kernel oops on port open
Date: Wed, 26 Feb 2014 08:41:38 -0500 [thread overview]
Message-ID: <1393422098-3727-1-git-send-email-markh@compro.net> (raw)
This patch addresses the follow error message followed
by a kernel oops:
dgap: driver does not set tty->port. This will crash the kernel later. Fix the driver
It also renames the main function this patch addresses because
its name is misleading.
Signed-off-by: Mark Hounschell <markh@compro.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/staging/dgap/dgap.c | 47 ++++++++++++++++++++++++++++++++++++---------
drivers/staging/dgap/dgap.h | 3 ++-
2 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 7cb1ad5..192f63a 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -223,7 +223,7 @@ static void dgap_get_vpd(struct board_t *brd);
static void dgap_do_reset_board(struct board_t *brd);
static void dgap_do_wait_for_bios(struct board_t *brd);
static void dgap_do_wait_for_fep(struct board_t *brd);
-static void dgap_sysfs_create(struct board_t *brd);
+static int dgap_tty_register_ports(struct board_t *brd);
static int dgap_firmware_load(struct pci_dev *pdev, int card_type);
/* Driver load/unload functions */
@@ -1098,7 +1098,9 @@ static int dgap_firmware_load(struct pci_dev *pdev, int card_type)
return ret;
}
- dgap_sysfs_create(brd);
+ ret = dgap_tty_register_ports(brd);
+ if (ret)
+ return ret;
brd->state = BOARD_READY;
brd->dpastatus = BD_RUNNING;
@@ -1730,6 +1732,7 @@ static void dgap_tty_uninit(struct board_t *brd)
dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
brd->dgap_Serial_Major = 0;
for (i = 0; i < brd->nasync; i++) {
+ tty_port_destroy(&brd->SerialPorts[i]);
dgap_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs);
tty_unregister_device(brd->SerialDriver, i);
}
@@ -1737,6 +1740,7 @@ static void dgap_tty_uninit(struct board_t *brd)
kfree(brd->SerialDriver->ttys);
brd->SerialDriver->ttys = NULL;
put_tty_driver(brd->SerialDriver);
+ kfree(brd->SerialPorts);
brd->dgap_Major_Serial_Registered = FALSE;
}
@@ -1744,6 +1748,7 @@ static void dgap_tty_uninit(struct board_t *brd)
dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
brd->dgap_TransparentPrint_Major = 0;
for (i = 0; i < brd->nasync; i++) {
+ tty_port_destroy(&brd->PrinterPorts[i]);
dgap_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs);
tty_unregister_device(brd->PrintDriver, i);
}
@@ -1751,6 +1756,7 @@ static void dgap_tty_uninit(struct board_t *brd)
kfree(brd->PrintDriver->ttys);
brd->PrintDriver->ttys = NULL;
put_tty_driver(brd->PrintDriver);
+ kfree(brd->PrinterPorts);
brd->dgap_Major_TransparentPrint_Registered = FALSE;
}
}
@@ -4813,25 +4819,48 @@ static int dgap_after_config_loaded(int board)
/*
* Create pr and tty device entries
*/
-static void dgap_sysfs_create(struct board_t *brd)
+static int dgap_tty_register_ports(struct board_t *brd)
{
struct channel_t *ch;
- int j = 0;
+ int i;
+
+ brd->SerialPorts = kcalloc(brd->nasync, sizeof(*brd->SerialPorts),
+ GFP_KERNEL);
+ if (brd->SerialPorts == NULL) {
+ pr_err("dgap: Cannot allocate serial port memory\n");
+ return -ENOMEM;
+ }
+ for (i = 0; i < brd->nasync; i++)
+ tty_port_init(&brd->SerialPorts[i]);
+
+ brd->PrinterPorts = kcalloc(brd->nasync, sizeof(*brd->PrinterPorts),
+ GFP_KERNEL);
+ if (brd->PrinterPorts == NULL) {
+ pr_err("dgap: Cannot allocate printer port memory\n");
+ return -ENOMEM;
+ }
+ for (i = 0; i < brd->nasync; i++)
+ tty_port_init(&brd->PrinterPorts[i]);
ch = brd->channels[0];
- for (j = 0; j < brd->nasync; j++, ch = brd->channels[j]) {
+ for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
struct device *classp;
- classp = tty_register_device(brd->SerialDriver, j,
- &(ch->ch_bd->pdev->dev));
+
+ classp = tty_port_register_device(&brd->SerialPorts[i],
+ brd->SerialDriver, brd->firstminor + i, NULL);
+
ch->ch_tun.un_sysfs = classp;
dgap_create_tty_sysfs(&ch->ch_tun, classp);
- classp = tty_register_device(brd->PrintDriver, j,
- &(ch->ch_bd->pdev->dev));
+ classp = tty_port_register_device(&brd->PrinterPorts[i],
+ brd->PrintDriver, brd->firstminor + i, NULL);
+
ch->ch_pun.un_sysfs = classp;
dgap_create_tty_sysfs(&ch->ch_pun, classp);
}
dgap_create_ports_sysfiles(brd);
+
+ return 0;
}
diff --git a/drivers/staging/dgap/dgap.h b/drivers/staging/dgap/dgap.h
index 573aa18..24db468 100644
--- a/drivers/staging/dgap/dgap.h
+++ b/drivers/staging/dgap/dgap.h
@@ -703,7 +703,6 @@ struct macounter
#define BD_FEP5PLUS 0x0001 /* Supports FEP5 Plus commands */
#define BD_HAS_VPD 0x0002 /* Board has VPD info available */
-
/*
* Per-board information
*/
@@ -761,8 +760,10 @@ struct board_t
struct channel_t *channels[MAXPORTS]; /* array of pointers to our channels. */
struct tty_driver *SerialDriver;
+ struct tty_port *SerialPorts;
char SerialName[200];
struct tty_driver *PrintDriver;
+ struct tty_port *PrinterPorts;
char PrintName[200];
u32 dgap_Major_Serial_Registered;
--
1.8.1.4
_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
next reply other threads:[~2014-02-26 13:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-26 13:41 Mark Hounschell [this message]
2014-02-26 14:01 ` [PATCH] staging: dgap: fix kernel oops on port open Dan Carpenter
[not found] ` <2072918892.118517.1393423307349.JavaMail.root@mx2.compro.net>
2014-02-26 14:15 ` Mark Hounschell
2014-02-26 15:18 ` [PATCH v2] " Mark Hounschell
2014-02-26 15:30 ` Dan Carpenter
[not found] ` <1913197851.119676.1393428700523.JavaMail.root@mx2.compro.net>
2014-02-27 20:39 ` Mark Hounschell
2014-02-27 21:00 ` Greg Kroah-Hartman
2014-02-27 21:13 ` Dan Carpenter
2014-02-27 21:52 ` Dan Carpenter
[not found] ` <1439681838.137312.1393537948833.JavaMail.root@mx2.compro.net>
2014-02-28 13:56 ` Mark Hounschell
2014-02-28 14:12 ` Dan Carpenter
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=1393422098-3727-1-git-send-email-markh@compro.net \
--to=markh@compro.net \
--cc=driverdev-devel@linuxdriverproject.org \
--cc=gregkh@linuxfoundation.org \
/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 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.