Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 29d56cfe authored by Jeff Dike's avatar Jeff Dike Committed by Linus Torvalds
Browse files

[PATCH] uml: hot-unplug code cleanup



Clean up the hot-unplugging code.  There is now an id procedure which is
called to figure out what device we're talking to.  The error messages from
that are now done from mconsole_remove instead of the driver.  remove is now
called with the device number, after it has been checked, so doesn't need to
do sanity checking on it.

Signed-off-by: default avatarJeff Dike <jdike@addtoit.com>
Cc: Paolo Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent fc47a0d1
Loading
Loading
Loading
Loading
+17 −2
Original line number Original line Diff line number Diff line
@@ -602,11 +602,26 @@ int line_get_config(char *name, struct line *lines, unsigned int num, char *str,
	return n;
	return n;
}
}


int line_remove(struct line *lines, unsigned int num, char *str)
int line_id(char **str, int *start_out, int *end_out)
{
	char *end;
        int n;

	n = simple_strtoul(*str, &end, 0);
	if((*end != '\0') || (end == *str))
                return -1;

        *str = end;
        *start_out = n;
        *end_out = n;
        return n;
}

int line_remove(struct line *lines, unsigned int num, int n)
{
{
	char config[sizeof("conxxxx=none\0")];
	char config[sizeof("conxxxx=none\0")];


	sprintf(config, "%s=none", str);
	sprintf(config, "%d=none", n);
	return !line_setup(lines, num, config, 0);
	return !line_setup(lines, num, config, 0);
}
}


+32 −4
Original line number Original line Diff line number Diff line
@@ -419,8 +419,9 @@ void mconsole_config(struct mc_request *req)
void mconsole_remove(struct mc_request *req)
void mconsole_remove(struct mc_request *req)
{
{
	struct mc_device *dev;	
	struct mc_device *dev;	
	char *ptr = req->request.data;
	char *ptr = req->request.data, *err_msg = "";
	int err;
        char error[256];
	int err, start, end, n;


	ptr += strlen("remove");
	ptr += strlen("remove");
	while(isspace(*ptr)) ptr++;
	while(isspace(*ptr)) ptr++;
@@ -429,8 +430,35 @@ void mconsole_remove(struct mc_request *req)
		mconsole_reply(req, "Bad remove option", 1, 0);
		mconsole_reply(req, "Bad remove option", 1, 0);
		return;
		return;
	}
	}
	err = (*dev->remove)(&ptr[strlen(dev->name)]);

	mconsole_reply(req, "", err, 0);
        ptr = &ptr[strlen(dev->name)];

        err = 1;
        n = (*dev->id)(&ptr, &start, &end);
        if(n < 0){
                err_msg = "Couldn't parse device number";
                goto out;
        }
        else if((n < start) || (n > end)){
                sprintf(error, "Invalid device number - must be between "
                        "%d and %d", start, end);
                err_msg = error;
                goto out;
        }

	err = (*dev->remove)(n);
        switch(err){
        case -ENODEV:
                err_msg = "Device doesn't exist";
                break;
        case -EBUSY:
                err_msg = "Device is currently open";
                break;
        default:
                break;
        }
 out:
	mconsole_reply(req, err_msg, err, 0);
}
}


#ifdef CONFIG_MAGIC_SYSRQ
#ifdef CONFIG_MAGIC_SYSRQ
+21 −10
Original line number Original line Diff line number Diff line
@@ -612,25 +612,35 @@ static int net_config(char *str)
	return(err);
	return(err);
}
}


static int net_remove(char *str)
static int net_id(char **str, int *start_out, int *end_out)
{
{
	struct uml_net *device;
	struct net_device *dev;
	struct uml_net_private *lp;
        char *end;
        char *end;
        int n;
        int n;


	n = simple_strtoul(str, &end, 0);
	n = simple_strtoul(*str, &end, 0);
	if((*end != '\0') || (end == str))
	if((*end != '\0') || (end == *str))
		return(-1);
		return -1;

        *start_out = n;
        *end_out = n;
        *str = end;
        return n;
}

static int net_remove(int n)
{
	struct uml_net *device;
	struct net_device *dev;
	struct uml_net_private *lp;


	device = find_device(n);
	device = find_device(n);
	if(device == NULL)
	if(device == NULL)
		return(0);
		return -ENODEV;


	dev = device->dev;
	dev = device->dev;
	lp = dev->priv;
	lp = dev->priv;
	if(lp->fd > 0) return(-1);
	if(lp->fd > 0)
                return -EBUSY;
	if(lp->remove != NULL) (*lp->remove)(&lp->user);
	if(lp->remove != NULL) (*lp->remove)(&lp->user);
	unregister_netdev(dev);
	unregister_netdev(dev);
	platform_device_unregister(&device->pdev);
	platform_device_unregister(&device->pdev);
@@ -638,13 +648,14 @@ static int net_remove(char *str)
	list_del(&device->list);
	list_del(&device->list);
	kfree(device);
	kfree(device);
	free_netdev(dev);
	free_netdev(dev);
	return(0);
	return 0;
}
}


static struct mc_device net_mc = {
static struct mc_device net_mc = {
	.name		= "eth",
	.name		= "eth",
	.config		= net_config,
	.config		= net_config,
	.get_config	= NULL,
	.get_config	= NULL,
        .id		= net_id,
	.remove		= net_remove,
	.remove		= net_remove,
};
};


+5 −4
Original line number Original line Diff line number Diff line
@@ -49,7 +49,7 @@ static struct chan_opts opts = {


static int ssl_config(char *str);
static int ssl_config(char *str);
static int ssl_get_config(char *dev, char *str, int size, char **error_out);
static int ssl_get_config(char *dev, char *str, int size, char **error_out);
static int ssl_remove(char *str);
static int ssl_remove(int n);


static struct line_driver driver = {
static struct line_driver driver = {
	.name 			= "UML serial line",
	.name 			= "UML serial line",
@@ -69,6 +69,7 @@ static struct line_driver driver = {
		.name  		= "ssl",
		.name  		= "ssl",
		.config 	= ssl_config,
		.config 	= ssl_config,
		.get_config 	= ssl_get_config,
		.get_config 	= ssl_get_config,
                .id		= line_id,
		.remove 	= ssl_remove,
		.remove 	= ssl_remove,
	},
	},
};
};
@@ -94,10 +95,10 @@ static int ssl_get_config(char *dev, char *str, int size, char **error_out)
			       str, size, error_out));
			       str, size, error_out));
}
}


static int ssl_remove(char *str)
static int ssl_remove(int n)
{
{
	return(line_remove(serial_lines, 
        return line_remove(serial_lines,
			   sizeof(serial_lines)/sizeof(serial_lines[0]), str));
                           sizeof(serial_lines)/sizeof(serial_lines[0]), n);
}
}


int ssl_open(struct tty_struct *tty, struct file *filp)
int ssl_open(struct tty_struct *tty, struct file *filp)
+4 −3
Original line number Original line Diff line number Diff line
@@ -55,7 +55,7 @@ static struct chan_opts opts = {


static int con_config(char *str);
static int con_config(char *str);
static int con_get_config(char *dev, char *str, int size, char **error_out);
static int con_get_config(char *dev, char *str, int size, char **error_out);
static int con_remove(char *str);
static int con_remove(int n);


static struct line_driver driver = {
static struct line_driver driver = {
	.name 			= "UML console",
	.name 			= "UML console",
@@ -75,6 +75,7 @@ static struct line_driver driver = {
		.name  		= "con",
		.name  		= "con",
		.config 	= con_config,
		.config 	= con_config,
		.get_config 	= con_get_config,
		.get_config 	= con_get_config,
                .id		= line_id,
		.remove 	= con_remove,
		.remove 	= con_remove,
	},
	},
};
};
@@ -99,9 +100,9 @@ static int con_get_config(char *dev, char *str, int size, char **error_out)
			       size, error_out));
			       size, error_out));
}
}


static int con_remove(char *str)
static int con_remove(int n)
{
{
	return(line_remove(vts, sizeof(vts)/sizeof(vts[0]), str));
        return line_remove(vts, sizeof(vts)/sizeof(vts[0]), n);
}
}


static int con_open(struct tty_struct *tty, struct file *filp)
static int con_open(struct tty_struct *tty, struct file *filp)
Loading