Commit d8475074 authored by Linus Torvalds's avatar Linus Torvalds

Make request_module() take a printf-like vararg argument instead of a string.

This is what a lot of the callers really wanted.
parent 3584199a
......@@ -23,7 +23,7 @@
*/
void crypto_alg_autoload(const char *name)
{
request_module(name);
request_module("%s", name);
}
struct crypto_alg *crypto_alg_mod_lookup(const char *name)
......
......@@ -367,9 +367,7 @@ extern int blk_dev_init(void);
static struct gendisk *base_probe(dev_t dev, int *part, void *data)
{
char name[30];
sprintf(name, "block-major-%d", MAJOR(dev));
request_module(name);
request_module("block-major-%d", MAJOR(dev));
return NULL;
}
......
......@@ -114,10 +114,8 @@ static int misc_open(struct inode * inode, struct file * file)
if (c != &misc_list)
new_fops = fops_get(c->fops);
if (!new_fops) {
char modname[20];
up(&misc_sem);
sprintf(modname, "char-major-%d-%d", MISC_MAJOR, minor);
request_module(modname);
request_module("char-major-%d-%d", MISC_MAJOR, minor);
down(&misc_sem);
c = misc_list.next;
while ((c != &misc_list) && (c->minor != minor))
......
......@@ -260,9 +260,7 @@ static int tty_set_ldisc(struct tty_struct *tty, int ldisc)
/* Eduardo Blanco <ejbs@cs.cs.com.uy> */
/* Cyrus Durgin <cider@speakeasy.org> */
if (!(ldiscs[ldisc].flags & LDISC_FLAG_DEFINED)) {
char modname [20];
sprintf(modname, "tty-ldisc-%d", ldisc);
request_module (modname);
request_module("tty-ldisc-%d", ldisc);
}
if (!(ldiscs[ldisc].flags & LDISC_FLAG_DEFINED))
return -EINVAL;
......
......@@ -58,14 +58,7 @@ static struct tt_internal *get_target_type(const char *name)
static void load_module(const char *name)
{
char module_name[DM_MOD_NAME_SIZE] = "dm-";
/* Length check for strcat() below */
if (strlen(name) > (DM_MOD_NAME_SIZE - 4))
return;
strcat(module_name, name);
request_module(module_name);
request_module("dm-%s", name);
}
struct target_type *dm_get_target_type(const char *name)
......
......@@ -1564,9 +1564,7 @@ static int do_md_run(mddev_t * mddev)
#ifdef CONFIG_KMOD
if (!pers[pnum])
{
char module_name[80];
sprintf (module_name, "md-personality-%d", pnum);
request_module (module_name);
request_module("md-personality-%d", pnum);
}
#endif
......
......@@ -83,11 +83,8 @@ static int video_open(struct inode *inode, struct file *file)
down(&videodev_lock);
vfl=video_device[minor];
if(vfl==NULL) {
char modname[20];
up(&videodev_lock);
sprintf (modname, "char-major-%d-%d", VIDEO_MAJOR, minor);
request_module(modname);
request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
down(&videodev_lock);
vfl=video_device[minor];
if (vfl==NULL) {
......
......@@ -64,7 +64,7 @@ struct mtd_info *do_map_probe(char *name, struct map_info *map)
drv = get_mtd_chip_driver(name);
if (!drv && !request_module(name))
if (!drv && !request_module("%s", name))
drv = get_mtd_chip_driver(name);
if (!drv)
......
......@@ -66,10 +66,7 @@ int sirdev_get_dongle(struct sir_dev *dev, IRDA_DONGLE type)
int err = -EINVAL;
#ifdef CONFIG_KMOD
char modname[30];
sprintf(modname, "irda-dongle-%d", type);
request_module(modname);
request_module("irda-dongle-%d", type);
#endif
if (dev->dongle_drv != NULL)
......
......@@ -1948,9 +1948,6 @@ ppp_set_compress(struct ppp *ppp, unsigned long arg)
struct ppp_option_data data;
void *state, *ostate;
unsigned char ccp_option[CCP_MAX_OPTION_LENGTH];
#ifdef CONFIG_KMOD
char modname[32];
#endif
err = -EFAULT;
if (copy_from_user(&data, (void *) arg, sizeof(data))
......@@ -1965,8 +1962,7 @@ ppp_set_compress(struct ppp *ppp, unsigned long arg)
cp = find_compressor(ccp_option[0]);
#ifdef CONFIG_KMOD
if (cp == 0) {
sprintf(modname, "ppp-compress-%d", ccp_option[0]);
request_module(modname);
request_module("ppp-compress-%d", ccp_option[0]);
cp = find_compressor(ccp_option[0]);
}
#endif /* CONFIG_KMOD */
......
......@@ -613,7 +613,6 @@ static int comx_write_proc(struct file *file, const char *buffer, u_long count,
char *page;
struct comx_hardware *hw = comx_channels;
struct comx_protocol *line = comx_lines;
char str[30];
int ret=0;
if (count > PAGE_SIZE) {
......@@ -691,8 +690,7 @@ static int comx_write_proc(struct file *file, const char *buffer, u_long count,
}
#ifdef CONFIG_KMOD
if(!hw && comx_strcasecmp(HWNAME_NONE,page) != 0){
sprintf(str,"comx-hw-%s",page);
request_module(str);
request_module("comx-hw-%s",page);
}
hw=comx_channels;
while (hw) {
......@@ -734,8 +732,7 @@ static int comx_write_proc(struct file *file, const char *buffer, u_long count,
}
#ifdef CONFIG_KMOD
if(!line && comx_strcasecmp(PROTONAME_NONE, page) != 0) {
sprintf(str,"comx-proto-%s",page);
request_module(str);
request_module("comx-proto-%s",page);
}
line=comx_lines;
while (line) {
......
......@@ -59,11 +59,8 @@ static int phone_open(struct inode *inode, struct file *file)
if (p)
new_fops = fops_get(p->f_op);
if (!new_fops) {
char modname[32];
up(&phone_lock);
sprintf(modname, "char-major-%d-%d", PHONE_MAJOR, minor);
request_module(modname);
request_module("char-major-%d-%d", PHONE_MAJOR, minor);
down(&phone_lock);
p = phone_device[minor];
if (p == NULL || (new_fops = fops_get(p->f_op)) == NULL)
......
......@@ -839,10 +839,7 @@ fb_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
#ifdef CONFIG_KMOD
static void try_to_load(int fb)
{
char modname[16];
sprintf(modname, "fb%d", fb);
request_module(modname);
request_module("fb%d", fb);
}
#endif /* CONFIG_KMOD */
......
......@@ -102,9 +102,7 @@ get_chrfops(unsigned int major, unsigned int minor)
#ifdef CONFIG_KMOD
if (!ret) {
char name[32];
sprintf(name, "char-major-%d", major);
request_module(name);
request_module("char-major-%d", major);
read_lock(&chrdevs_lock);
ret = lookup_chrfops(major, minor);
......
......@@ -1034,14 +1034,12 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
#ifdef CONFIG_KMOD
}else{
#define printable(c) (((c)=='\t') || ((c)=='\n') || (0x20<=(c) && (c)<=0x7e))
char modname[20];
if (printable(bprm->buf[0]) &&
printable(bprm->buf[1]) &&
printable(bprm->buf[2]) &&
printable(bprm->buf[3]))
break; /* -ENOEXEC */
sprintf(modname, "binfmt-%04x", *(unsigned short *)(&bprm->buf[2]));
request_module(modname);
request_module("binfmt-%04x", *(unsigned short *)(&bprm->buf[2]));
#endif
}
}
......
......@@ -279,7 +279,7 @@ struct file_system_type *get_fs_type(const char *name)
if (fs && !try_module_get(fs->owner))
fs = NULL;
read_unlock(&file_systems_lock);
if (!fs && (request_module(name) == 0)) {
if (!fs && (request_module("%s", name) == 0)) {
read_lock(&file_systems_lock);
fs = *(find_filesystem(name));
if (fs && !try_module_get(fs->owner))
......
......@@ -217,7 +217,6 @@ struct nls_table *load_nls(char *charset)
{
struct nls_table *nls;
#ifdef CONFIG_KMOD
char buf[40];
int ret;
#endif
......@@ -226,14 +225,7 @@ struct nls_table *load_nls(char *charset)
return nls;
#ifdef CONFIG_KMOD
if (strlen(charset) > sizeof(buf) - sizeof("nls_")) {
printk("Unable to load NLS charset %s: name too long\n",
charset);
return NULL;
}
sprintf(buf, "nls_%s", charset);
ret = request_module(buf);
ret = request_module("nls_%s", charset);
if (ret != 0) {
printk("Unable to load NLS charset %s\n", charset);
return NULL;
......
......@@ -24,12 +24,12 @@
#include <linux/compiler.h>
#ifdef CONFIG_KMOD
extern int request_module(const char * name);
extern int request_module(const char * name, ...) __attribute__ ((format (printf, 1, 2)));
#else
static inline int request_module(const char * name) { return -ENOSYS; }
static inline int request_module(const char * name, ...) { return -ENOSYS; }
#endif
#define try_then_request_module(x, mod) ((x) ?: request_module(mod), (x))
#define try_then_request_module(x, mod...) ((x) ?: request_module(mod), (x))
extern int call_usermodehelper(char *path, char *argv[], char *envp[], int wait);
#ifdef CONFIG_HOTPLUG
......
......@@ -88,11 +88,7 @@ lookup_exec_domain(u_long personality)
#ifdef CONFIG_KMOD
read_unlock(&exec_domains_lock);
{
char buffer[30];
sprintf(buffer, "personality-%ld", pers);
request_module(buffer);
}
request_module("personality-%ld", pers);
read_lock(&exec_domains_lock);
for (ep = exec_domains; ep; ep = ep->next) {
......
......@@ -143,7 +143,7 @@ const void *inter_module_get_request(const char *im_name, const char *modname)
{
const void *result = inter_module_get(im_name);
if (!result) {
request_module(modname);
request_module("%s", modname);
result = inter_module_get(im_name);
}
return(result);
......
......@@ -58,11 +58,14 @@ char modprobe_path[256] = "/sbin/modprobe";
* If module auto-loading support is disabled then this function
* becomes a no-operation.
*/
int request_module(const char *module_name)
#define MODULENAME_SIZE 32
int request_module(const char *fmt, ...)
{
va_list args;
char module_name[MODULENAME_SIZE];
unsigned int max_modprobes;
int ret;
char *argv[] = { modprobe_path, "--", (char*)module_name, NULL };
char *argv[] = { modprobe_path, "--", module_name, NULL };
static char *envp[] = { "HOME=/",
"TERM=linux",
"PATH=/sbin:/usr/sbin:/bin:/usr/bin",
......@@ -71,6 +74,12 @@ int request_module(const char *module_name)
#define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
static int kmod_loop_msg;
va_start(args, fmt);
ret = vsnprintf(module_name, MODULENAME_SIZE, fmt, args);
va_end(args);
if (ret >= MODULENAME_SIZE)
return -ENAMETOOLONG;
/* If modprobe needs a service that is in a module, we get a recursive
* loop. Limit the number of running kmod threads to max_threads/2 or
* MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
......@@ -80,7 +89,6 @@ int request_module(const char *module_name)
* and it is not worth changing the proc code just to handle this case.
* KAO.
*
* "trace the ppid" is simple, but will fail if someone's
* parent exits. I think this is as good as it gets. --RR
*/
......
......@@ -99,9 +99,7 @@ static int bt_sock_create(struct socket *sock, int proto)
#if defined(CONFIG_KMOD)
if (!bt_proto[proto]) {
char module_name[30];
sprintf(module_name, "bt-proto-%d", proto);
request_module(module_name);
request_module("bt-proto-%d", proto);
}
#endif
err = -EPROTONOSUPPORT;
......
......@@ -319,10 +319,7 @@ find_inlist_lock(struct list_head *head, const char *name, const char *prefix,
ret = find_inlist_lock_noload(head, name, error, mutex);
if (!ret) {
char modulename[EBT_FUNCTION_MAXNAMELEN + strlen(prefix) + 1];
strcpy(modulename, prefix);
strcat(modulename, name);
request_module(modulename);
request_module("%s%s", prefix, name);
ret = find_inlist_lock_noload(head, name, error, mutex);
}
return ret;
......
......@@ -721,7 +721,7 @@ void netdev_state_change(struct net_device *dev)
void dev_load(const char *name)
{
if (!dev_get(name) && capable(CAP_SYS_MODULE))
request_module(name);
request_module("%s", name);
}
#else
......
......@@ -371,11 +371,8 @@ find_inlist_lock(struct list_head *head,
ret = find_inlist_lock_noload(head, name, error, mutex);
if (!ret) {
char modulename[ARPT_FUNCTION_MAXNAMELEN + strlen(prefix) + 1];
strcpy(modulename, prefix);
strcat(modulename, name);
duprintf("find_inlist: loading `%s'.\n", modulename);
request_module(modulename);
duprintf("find_inlist: loading `%s%s'.\n", prefix, name);
request_module("%s%s", prefix, name);
ret = find_inlist_lock_noload(head, name, error, mutex);
}
......
......@@ -426,7 +426,7 @@ int ip_nat_helper_register(struct ip_nat_helper *me)
tmp += 6;
sprintf(name, "ip_conntrack%s", tmp);
#ifdef CONFIG_KMOD
if (!request_module(name)
if (!request_module("ip_conntrack%s", tmp)
&& (ct_helper = ip_ct_find_helper(&me->tuple))) {
if (!try_module_get(ct_helper->me))
return -EBUSY;
......
......@@ -454,11 +454,8 @@ find_inlist_lock(struct list_head *head,
ret = find_inlist_lock_noload(head, name, error, mutex);
if (!ret) {
char modulename[IPT_FUNCTION_MAXNAMELEN + strlen(prefix) + 1];
strcpy(modulename, prefix);
strcat(modulename, name);
duprintf("find_inlist: loading `%s'.\n", modulename);
request_module(modulename);
duprintf("find_inlist: loading `%s%s'.\n", prefix, name);
request_module("%s%s", prefix, name);
ret = find_inlist_lock_noload(head, name, error, mutex);
}
......
......@@ -527,11 +527,8 @@ find_inlist_lock(struct list_head *head,
ret = find_inlist_lock_noload(head, name, error, mutex);
if (!ret) {
char modulename[IP6T_FUNCTION_MAXNAMELEN + strlen(prefix) + 1];
strcpy(modulename, prefix);
strcat(modulename, name);
duprintf("find_inlist: loading `%s'.\n", modulename);
request_module(modulename);
duprintf("find_inlist: loading `%s%s'.\n", prefix, name);
request_module("%s%s", prefix, name);
ret = find_inlist_lock_noload(head, name, error, mutex);
}
......
......@@ -433,13 +433,9 @@ dongle_t *irda_device_dongle_init(struct net_device *dev, int type)
ASSERT(dev != NULL, return NULL;);
#ifdef CONFIG_KMOD
{
char modname[32];
ASSERT(!in_interrupt(), return NULL;);
/* Try to load the module needed */
sprintf(modname, "irda-dongle-%d", type);
request_module(modname);
}
request_module("irda-dongle-%d", type);
#endif
if (!(reg = hashbin_lock_find(dongles, type, NULL))) {
......
......@@ -204,11 +204,9 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, void *arg)
#ifdef CONFIG_KMOD
if (tp_ops==NULL && tca[TCA_KIND-1] != NULL) {
struct rtattr *kind = tca[TCA_KIND-1];
char module_name[4 + IFNAMSIZ + 1];
if (RTA_PAYLOAD(kind) <= IFNAMSIZ) {
sprintf(module_name, "cls_%s", (char*)RTA_DATA(kind));
request_module (module_name);
request_module("cls_%s", (char*)RTA_DATA(kind));
tp_ops = tcf_proto_lookup_ops(kind);
}
}
......
......@@ -396,11 +396,8 @@ qdisc_create(struct net_device *dev, u32 handle, struct rtattr **tca, int *errp)
ops = qdisc_lookup_ops(kind);
#ifdef CONFIG_KMOD
if (ops==NULL && tca[TCA_KIND-1] != NULL) {
char module_name[4 + IFNAMSIZ + 1];
if (RTA_PAYLOAD(kind) <= IFNAMSIZ) {
sprintf(module_name, "sch_%s", (char*)RTA_DATA(kind));
request_module (module_name);
request_module("sch_%s", (char*)RTA_DATA(kind));
ops = qdisc_lookup_ops(kind);
}
}
......
......@@ -1034,9 +1034,7 @@ int sock_create(int family, int type, int protocol, struct socket **res)
*/
if (net_families[family]==NULL)
{
char module_name[30];
sprintf(module_name,"net-pf-%d",family);
request_module(module_name);
request_module("net-pf-%d",family);
}
#endif
......
......@@ -136,7 +136,6 @@ client_t *snd_seq_client_use_ptr(int clientid)
static char card_requested[SNDRV_CARDS];
if (clientid < 64) {
int idx;
char name[32];
if (! client_requested[clientid]) {
client_requested[clientid] = 1;
......@@ -144,8 +143,7 @@ client_t *snd_seq_client_use_ptr(int clientid)
if (seq_client_load[idx] < 0)
break;
if (seq_client_load[idx] == clientid) {
sprintf(name, "snd-seq-client-%i", clientid);
request_module(name);
request_module("snd-seq-client-%i", clientid);
break;
}
}
......
......@@ -131,7 +131,6 @@ void snd_seq_device_load_drivers(void)
{
#ifdef CONFIG_KMOD
struct list_head *head;
char modname[64];
down(&ops_mutex);
list_for_each(head, &opslist) {
......@@ -141,8 +140,7 @@ void snd_seq_device_load_drivers(void)
ops->used++;
up(&ops_mutex);
ops->driver |= DRIVER_REQUESTED;
sprintf(modname, "snd-%s", ops->id);
request_module(modname);
request_module("snd-%s", ops->id);
down(&ops_mutex);
ops->used--;
}
......
......@@ -79,7 +79,6 @@ static DECLARE_MUTEX(sound_mutex);
*/
void snd_request_card(int card)
{
char str[32];
int locked;
read_lock(&snd_card_rwlock);
......@@ -89,8 +88,7 @@ void snd_request_card(int card)
return;
if (card < 0 || card >= cards_limit)
return;
sprintf(str, "snd-card-%i", card);
request_module(str);
request_module("snd-card-%i", card);
}
static void snd_request_other(int minor)
......
......@@ -216,9 +216,7 @@ static int sound_open(struct inode *inode, struct file *file)
case SND_DEV_CTL:
dev >>= 4;
if (dev >= 0 && dev < MAX_MIXER_DEV && mixer_devs[dev] == NULL) {
char modname[20];
sprintf(modname, "mixer%d", dev);
request_module(modname);
request_module("mixer%d", dev);
}
if (dev && (dev >= num_mixers || mixer_devs[dev] == NULL))
return -ENXIO;
......@@ -318,9 +316,7 @@ static int sound_mixer_ioctl(int mixdev, unsigned int cmd, caddr_t arg)
return -ENXIO;
/* Try to load the mixer... */
if (mixer_devs[mixdev] == NULL) {
char modname[20];
sprintf(modname, "mixer%d", mixdev);
request_module(modname);
request_module("mixer%d", mixdev);
}
if (mixdev >= num_mixers || !mixer_devs[mixdev])
return -ENXIO;
......
......@@ -500,8 +500,6 @@ int soundcore_open(struct inode *inode, struct file *file)
if (s)
new_fops = fops_get(s->unit_fops);
if (!new_fops) {
char mod[32];
spin_unlock(&sound_loader_lock);
/*
* Please, don't change this order or code.
......@@ -510,10 +508,8 @@ int soundcore_open(struct inode *inode, struct file *file)
* ALSA toplevel modules for soundcards, thus we need
* load them at first. [Jaroslav Kysela <perex@jcu.cz>]
*/
sprintf(mod, "sound-slot-%i", unit>>4);
request_module(mod);
sprintf(mod, "sound-service-%i-%i", unit>>4, chain);
request_module(mod);
request_module("sound-slot-%i", unit>>4);
request_module("sound-service-%i-%i", unit>>4, chain);
spin_lock(&sound_loader_lock);
s = __look_for_unit(chain, unit);
if (s)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment