From: Kevin Corry <kevcorry@us.ibm.com>
To: torvalds@osdl.org, akpm@zip.com.au, thornber@sistina.com
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] DM 6/6: Support arbitrary number of target params
Date: Mon, 22 Sep 2003 10:53:08 -0500 [thread overview]
Message-ID: <200309221053.08510.kevcorry@us.ibm.com> (raw)
In-Reply-To: <200309221044.21694.kevcorry@us.ibm.com>
Support an arbitrary number of target parameters. [Alasdair Kergon]
--- diff/drivers/md/dm-table.c 2003-09-17 12:28:06.000000000 +0100
+++ source/drivers/md/dm-table.c 2003-09-17 13:09:41.000000000 +0100
@@ -534,12 +534,36 @@
}
/*
+ * Used to dynamically allocate the arg array.
+ */
+static char **realloc_argv(unsigned *array_size, char **old_argv)
+{
+ char **argv;
+ unsigned new_size;
+
+ new_size = *array_size ? *array_size * 2 : 64;
+ argv = kmalloc(new_size * sizeof(*argv), GFP_KERNEL);
+ if (argv) {
+ memcpy(argv, old_argv, *array_size * sizeof(*argv));
+ *array_size = new_size;
+ }
+
+ kfree(old_argv);
+ return argv;
+}
+
+/*
* Destructively splits up the argument list to pass to ctr.
*/
-static int split_args(int max, int *argc, char **argv, char *input)
+static int split_args(int *argc, char ***argvp, char *input)
{
- char *start, *end = input, *out;
+ char *start, *end = input, *out, **argv = NULL;
+ unsigned array_size = 0;
+
*argc = 0;
+ argv = realloc_argv(&array_size, argv);
+ if (!argv)
+ return -ENOMEM;
while (1) {
start = end;
@@ -568,8 +592,11 @@
}
/* have we already filled the array ? */
- if ((*argc + 1) > max)
- return -EINVAL;
+ if ((*argc + 1) > array_size) {
+ argv = realloc_argv(&array_size, argv);
+ if (!argv)
+ return -ENOMEM;
+ }
/* we know this is whitespace */
if (*end)
@@ -581,6 +608,7 @@
(*argc)++;
}
+ *argvp = argv;
return 0;
}
@@ -588,7 +616,7 @@
sector_t start, sector_t len, char *params)
{
int r = -EINVAL, argc;
- char *argv[32];
+ char **argv;
struct dm_target *tgt;
if ((r = check_space(t)))
@@ -617,13 +645,14 @@
goto bad;
}
- r = split_args(ARRAY_SIZE(argv), &argc, argv, params);
+ r = split_args(&argc, &argv, params);
if (r) {
- tgt->error = "couldn't split parameters";
+ tgt->error = "couldn't split parameters (insufficient memory)";
goto bad;
}
r = tgt->type->ctr(tgt, argc, argv);
+ kfree(argv);
if (r)
goto bad;
prev parent reply other threads:[~2003-09-22 15:55 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-22 15:44 2.6.0-test5-mm2 Device Mapper Patches Kevin Corry
2003-09-22 15:51 ` [PATCH] DM 1/6: Use new format_dev_t macro Kevin Corry
2003-09-22 19:29 ` viro
2003-09-23 7:57 ` Joe Thornber
2003-09-23 7:57 ` viro
2003-09-23 14:07 ` Kevin Corry
2003-09-22 15:51 ` [PATCH] DM 2/6: Drop extra table ref-count Kevin Corry
2003-09-22 15:52 ` [PATCH] DM 3/6: Move retrieve_status function Kevin Corry
2003-09-22 15:52 ` [PATCH] DM 4/6: Return table status for dev_wait Kevin Corry
2003-09-22 15:52 ` [PATCH] DM 5/6: Message fix in dm-linear Kevin Corry
2003-09-22 15:53 ` Kevin Corry [this message]
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=200309221053.08510.kevcorry@us.ibm.com \
--to=kevcorry@us.ibm.com \
--cc=akpm@zip.com.au \
--cc=linux-kernel@vger.kernel.org \
--cc=thornber@sistina.com \
--cc=torvalds@osdl.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox