From: Daeseok Youn <daeseok.youn@gmail.com>
To: lidza.louina@gmail.com, markh@compro.net
Cc: markh@compro.net, daeseok.youn@gmail.com,
gregkh@linuxfoundation.org,
driverdev-devel@linuxdriverproject.org,
devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: [PATCH 4/4] staging: dgap: introducing find_board_by_major()
Date: Thu, 6 Nov 2014 19:27:59 +0900 [thread overview]
Message-ID: <20141106102759.GA21472@devel> (raw)
use find_board_by_major function instead of getting a brd from static
arrary. Becasue tty's major number doesn't start zero and we can
find a brd from dgap_board[].
Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>
---
drivers/staging/dgap/dgap.c | 28 +++++++++++++++++-----------
1 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/drivers/staging/dgap/dgap.c b/drivers/staging/dgap/dgap.c
index 3f23e5b..f38354f 100644
--- a/drivers/staging/dgap/dgap.c
+++ b/drivers/staging/dgap/dgap.c
@@ -80,7 +80,6 @@ static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
static struct class *dgap_class;
-static struct board_t *dgap_boards_by_major[256];
static uint dgap_count = 500;
/*
@@ -4409,6 +4408,22 @@ static void dgap_tty_unthrottle(struct tty_struct *tty)
spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
}
+static struct board_t *find_board_by_major(unsigned int major)
+{
+ unsigned int i;
+
+ for (i = 0; i < MAXBOARDS; i++) {
+ struct board_t *brd = dgap_board[i];
+ if (!brd)
+ return NULL;
+ if (major == brd->serial_driver->major ||
+ major == brd->print_driver->major)
+ return brd;
+ }
+
+ return NULL;
+}
+
/************************************************************************
*
* TTY Entry points and helper functions
@@ -4435,11 +4450,7 @@ static int dgap_tty_open(struct tty_struct *tty, struct file *file)
major = MAJOR(tty_devnum(tty));
minor = MINOR(tty_devnum(tty));
- if (major > 255)
- return -EIO;
-
- /* Get board pointer from our array of majors we have allocated */
- brd = dgap_boards_by_major[major];
+ brd = find_board_by_major(major);
if (!brd)
return -EIO;
@@ -5301,9 +5312,6 @@ static int dgap_tty_register(struct board_t *brd)
if (rc < 0)
goto unregister_serial_drv;
- dgap_boards_by_major[brd->serial_driver->major] = brd;
- dgap_boards_by_major[brd->print_driver->major] = brd;
-
return 0;
unregister_serial_drv:
@@ -6559,7 +6567,6 @@ static void dgap_cleanup_tty(struct board_t *brd)
struct device *dev;
unsigned int i;
- dgap_boards_by_major[brd->serial_driver->major] = NULL;
for (i = 0; i < brd->nasync; i++) {
tty_port_destroy(&brd->serial_ports[i]);
dev = brd->channels[i]->ch_tun.un_sysfs;
@@ -6570,7 +6577,6 @@ static void dgap_cleanup_tty(struct board_t *brd)
put_tty_driver(brd->serial_driver);
kfree(brd->serial_ports);
- dgap_boards_by_major[brd->print_driver->major] = NULL;
for (i = 0; i < brd->nasync; i++) {
tty_port_destroy(&brd->printer_ports[i]);
dev = brd->channels[i]->ch_pun.un_sysfs;
--
1.7.1
reply other threads:[~2014-11-06 10:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20141106102759.GA21472@devel \
--to=daeseok.youn@gmail.com \
--cc=devel@driverdev.osuosl.org \
--cc=driverdev-devel@linuxdriverproject.org \
--cc=gregkh@linuxfoundation.org \
--cc=lidza.louina@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=markh@compro.net \
/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.