All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adam Belay <ambx1@neo.rr.com>
To: linux-kernel@vger.kernel.org
Cc: greg@kroah.com, Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Jaroslav Kysela <perex@perex.cz>
Subject: [PATCH][RFC] PnP BIOS cleanups (4/4)
Date: Sun, 2 Feb 2003 20:36:56 +0000	[thread overview]
Message-ID: <20030202203656.GA23160@neo.rr.com> (raw)

This patch cleans up device inserting and disabling.


--- a/drivers/pnp/pnpbios/core.c	Sun Feb  2 18:43:34 2003
+++ b/drivers/pnp/pnpbios/core.c	Sun Feb  2 19:19:13 2003
@@ -236,6 +236,7 @@
 	void *p = kmalloc( size, f );
 	if ( p == NULL )
 		printk(KERN_ERR "PnPBIOS: kmalloc() failed\n");
+	memset(p, 0, size);
 	return p;
 }
 
@@ -752,8 +753,10 @@
 	node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL);
 	if (!node)
 		return -1;
-	if (pnp_bios_get_dev_node(&nodenum, (char )0, node))
+	if (pnp_bios_get_dev_node(&nodenum, (char )0, node)) {
+		kfree(node);
 		return -ENODEV;
+	}
 	pnp_parse_current_resources((char *)node->data,(char *)node->data + node->size,res);
 	dev->active = pnp_is_active(dev);
 	kfree(node);
@@ -777,6 +780,7 @@
 	if (pnp_bios_get_dev_node(&nodenum, (char )1, node))
 		return -ENODEV;
 	if(!pnp_write_resources((char *)node->data,(char *)node->data + node->size,res)){
+		kfree(node);
 		return -1;
 	}
 	pnp_bios_set_dev_node(node->handle, (char)0, node);
@@ -786,70 +790,24 @@
 
 static int pnpbios_disable_resources(struct pnp_dev *dev)
 {
-	struct pnp_rule_table * config = kmalloc(sizeof(struct pnp_rule_table), GFP_KERNEL);
-	/* first we need to set everything to a disabled value */
-	struct pnp_port	port = {
-	.max	= 0,
-	.min	= 0,
-	.align	= 0,
-	.size	= 0,
-	.flags	= 0,
-	.pad	= 0,
-	};
-	struct pnp_mem	mem = {
-	.max	= 0,
-	.min	= 0,
-	.align	= 0,
-	.size	= 0,
-	.flags	= 0,
-	};
-	struct pnp_dma	dma = {
-	.map	= 0,
-	.flags	= 0,
-	};
-	struct pnp_irq	irq = {
-	.map	= 0,
-	.flags	= 0,
-	.pad	= 0,
-	};
-	int i;
 	struct pnp_dev_node_info node_info;
-	u8 nodenum = dev->number;
 	struct pnp_bios_node * node;
-	if (!config)
-		return -1;
+	
 	/* just in case */
 	if(dev->flags & PNPBIOS_NO_DISABLE || !pnpbios_is_dynamic(dev))
 		return -EPERM;
-	memset(config, 0, sizeof(struct pnp_rule_table));
 	if (!dev || !dev->active)
 		return -EINVAL;
-	for (i=0; i < 8; i++)
-		config->port[i] = &port;
-	for (i=0; i < 4; i++)
-		config->mem[i] = &mem;
-	for (i=0; i < 2; i++)
-		config->irq[i] = &irq;
-	for (i=0; i < 2; i++)
-		config->dma[i] = &dma;
-	dev->active = 0;
-
 	if (pnp_bios_dev_node_info(&node_info) != 0)
 		return -ENODEV;
+	/* the value of this will be zero */
 	node = pnpbios_kmalloc(node_info.max_node_size, GFP_KERNEL);
 	if (!node)
-		return -1;
-	if (pnp_bios_get_dev_node(&nodenum, (char )1, node))
-		goto failed;
-	if(pnp_write_resources((char *)node->data,(char *)node->data + node->size,&dev->res)<0)
-		goto failed;
-	kfree(config);
+		return -ENOMEM;
+	pnp_bios_set_dev_node(node->handle, (char)0, node);
+	dev->active = 0;
 	kfree(node);
 	return 0;
- failed:
-	kfree(node);
-	kfree(config);
-	return -1;
 }
 
 
@@ -862,15 +820,47 @@
 	.disable = pnpbios_disable_resources,
 };
 
-static inline int insert_device(struct pnp_dev *dev)
+static int insert_device(struct pnp_dev *dev, struct pnp_bios_node * node)
 {
 	struct list_head * pos;
+	unsigned char * p;
 	struct pnp_dev * pnp_dev;
+	struct pnp_id *dev_id;
+	char id[8];
+
+	/* check if the device is already added */
+	dev->number = node->handle;
 	list_for_each (pos, &pnpbios_protocol.devices){
 		pnp_dev = list_entry(pos, struct pnp_dev, protocol_list);
 		if (dev->number == pnp_dev->number)
 			return -1;
 	}
+
+	/* set the initial values for the PnP device */
+	dev_id = pnpbios_kmalloc(sizeof(struct pnp_id), GFP_KERNEL);
+	if (!dev_id)
+		return -1;
+	pnpid32_to_pnpid(node->eisa_id,id);
+	memcpy(dev_id->id,id,7);
+	pnp_add_id(dev_id, dev);
+	p = pnp_parse_current_resources((char *)node->data,
+		(char *)node->data + node->size,&dev->res);
+	p = pnp_parse_possible_resources((char *)p,
+		(char *)node->data + node->size,dev);
+	node_id_data_to_dev(p,node,dev);
+	dev->active = pnp_is_active(dev);
+	dev->flags = node->flags;
+	if (!(dev->flags & PNPBIOS_NO_CONFIG))
+		dev->capabilities |= PNP_CONFIGURABLE;
+	if (!(dev->flags & PNPBIOS_NO_DISABLE))
+		dev->capabilities |= PNP_DISABLE;
+	dev->capabilities |= PNP_READ;
+	if (pnpbios_is_dynamic(dev))
+		dev->capabilities |= PNP_WRITE;
+	if (dev->flags & PNPBIOS_REMOVABLE)
+		dev->capabilities |= PNP_REMOVABLE;
+	dev->protocol = &pnpbios_protocol;
+
 	pnp_add_device(dev);
 	return 0;
 }
@@ -878,14 +868,11 @@
 static void __init build_devlist(void)
 {
 	u8 nodenum;
-	char id[8];
-	unsigned char *pos;
 	unsigned int nodes_got = 0;
 	unsigned int devs = 0;
 	struct pnp_bios_node *node;
 	struct pnp_dev_node_info node_info;
 	struct pnp_dev *dev;
-	struct pnp_id *dev_id;
 
 	if (!pnp_bios_present())
 		return;
@@ -912,38 +899,9 @@
 		dev =  pnpbios_kmalloc(sizeof (struct pnp_dev), GFP_KERNEL);
 		if (!dev)
 			break;
-		memset(dev,0,sizeof(struct pnp_dev));
-		dev_id =  pnpbios_kmalloc(sizeof (struct pnp_id), GFP_KERNEL);
-		if (!dev_id) {
-			kfree(dev);
-			break;
-		}
-		memset(dev_id,0,sizeof(struct pnp_id));
-		dev->number = thisnodenum;
-		pnpid32_to_pnpid(node->eisa_id,id);
-		memcpy(dev_id->id,id,7);
-		pnp_add_id(dev_id, dev);
-		pos = pnp_parse_current_resources((char *)node->data,(char *)node->data + node->size,&dev->res);
-		pos = pnp_parse_possible_resources((char *)pos,(char *)node->data + node->size,dev);
-		node_id_data_to_dev(pos,node,dev);
-		dev->active = pnp_is_active(dev);
-		dev->flags = node->flags;
-		if (!(dev->flags & PNPBIOS_NO_CONFIG))
-			dev->capabilities |= PNP_CONFIGURABLE;
-		if (!(dev->flags & PNPBIOS_NO_DISABLE))
-			dev->capabilities |= PNP_DISABLE;
-		dev->capabilities |= PNP_READ;
-		if (pnpbios_is_dynamic(dev))
-			dev->capabilities |= PNP_WRITE;
-		if (dev->flags & PNPBIOS_REMOVABLE)
-			dev->capabilities |= PNP_REMOVABLE;
-
-		dev->protocol = &pnpbios_protocol;
-
-		if(insert_device(dev)<0) {
-			kfree(dev_id);
+		if(insert_device(dev,node)<0)
 			kfree(dev);
-		} else
+		else
 			devs++;
 		if (nodenum <= thisnodenum) {
 			printk(KERN_ERR "PnPBIOS: build_devlist: Node number 0x%x is out of sequence following node 0x%x. Aborting.\n", (unsigned int)nodenum, (unsigned int)thisnodenum);

             reply	other threads:[~2003-02-03  1:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-02 20:36 Adam Belay [this message]
2003-02-03  6:36 ` [PATCH][RFC] PnP BIOS cleanups (4/4) Denis Vlasenko

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=20030202203656.GA23160@neo.rr.com \
    --to=ambx1@neo.rr.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    /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.