From: Bjorn Helgaas <bjorn.helgaas@hp.com>
To: Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
Adam Belay <ambx1@neo.rr.com>, Adam M Belay <abelay@mit.edu>,
Li Shaohua <shaohua.li@intel.com>,
Matthieu Castet <castet.matthieu@free.fr>,
Thomas Renninger <trenn@suse.de>,
Rene Herman <rene.herman@keyaccess.nl>,
Jaroslav Kysela <perex@perex.cz>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [patch 07/54] PNP: add pnp_alloc_dev()
Date: Fri, 25 Apr 2008 12:38:14 -0600 [thread overview]
Message-ID: <20080425183925.542039833@ldl.fc.hp.com> (raw)
In-Reply-To: 20080425183807.366134771@ldl.fc.hp.com
[-- Attachment #1: pnp-alloc-dev --]
[-- Type: text/plain, Size: 6235 bytes --]
Add pnp_alloc_dev() to allocate a struct pnp_dev and fill in the
protocol, instance number, and initial PNP ID. Now it is always
valid to use dev_printk() on any pnp_dev pointer.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
---
drivers/pnp/base.h | 1 +
drivers/pnp/core.c | 38 +++++++++++++++++++++++++++++++-------
drivers/pnp/isapnp/core.c | 11 +++++------
drivers/pnp/pnpacpi/core.c | 19 +++----------------
drivers/pnp/pnpbios/core.c | 13 ++-----------
5 files changed, 42 insertions(+), 40 deletions(-)
Index: work10/drivers/pnp/base.h
===================================================================
--- work10.orig/drivers/pnp/base.h 2008-04-25 11:14:48.000000000 -0600
+++ work10/drivers/pnp/base.h 2008-04-25 11:14:49.000000000 -0600
@@ -2,6 +2,7 @@
void *pnp_alloc(long size);
#define PNP_EISA_ID_MASK 0x7fffffff
void pnp_eisa_id_to_string(u32 id, char *str);
+struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
int pnp_interface_attach_device(struct pnp_dev *dev);
void pnp_fixup_device(struct pnp_dev *dev);
Index: work10/drivers/pnp/core.c
===================================================================
--- work10.orig/drivers/pnp/core.c 2008-04-25 11:12:17.000000000 -0600
+++ work10/drivers/pnp/core.c 2008-04-25 11:14:49.000000000 -0600
@@ -109,15 +109,42 @@
kfree(dev);
}
-int __pnp_add_device(struct pnp_dev *dev)
+struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid)
{
- int ret;
+ struct pnp_dev *dev;
+ struct pnp_id *dev_id;
- pnp_fixup_device(dev);
+ dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
+ if (!dev)
+ return NULL;
+
+ dev->protocol = protocol;
+ dev->number = id;
+ dev->dma_mask = DMA_24BIT_MASK;
+
+ dev->dev.parent = &dev->protocol->dev;
dev->dev.bus = &pnp_bus_type;
dev->dev.dma_mask = &dev->dma_mask;
- dev->dma_mask = dev->dev.coherent_dma_mask = DMA_24BIT_MASK;
+ dev->dev.coherent_dma_mask = dev->dma_mask;
dev->dev.release = &pnp_release_device;
+
+ sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
+ dev->number);
+
+ dev_id = pnp_add_id(dev, pnpid);
+ if (!dev_id) {
+ kfree(dev);
+ return NULL;
+ }
+
+ return dev;
+}
+
+int __pnp_add_device(struct pnp_dev *dev)
+{
+ int ret;
+
+ pnp_fixup_device(dev);
dev->status = PNP_READY;
spin_lock(&pnp_lock);
list_add_tail(&dev->global_list, &pnp_global);
@@ -145,9 +172,6 @@
if (dev->card)
return -EINVAL;
- dev->dev.parent = &dev->protocol->dev;
- sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
- dev->number);
ret = __pnp_add_device(dev);
if (ret)
return ret;
Index: work10/drivers/pnp/isapnp/core.c
===================================================================
--- work10.orig/drivers/pnp/isapnp/core.c 2008-04-25 11:14:48.000000000 -0600
+++ work10/drivers/pnp/isapnp/core.c 2008-04-25 11:14:49.000000000 -0600
@@ -409,18 +409,17 @@
char id[8];
isapnp_peek(tmp, size);
- dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
- if (!dev)
- return NULL;
- dev->number = number;
eisa_id = tmp[0] | tmp[1] << 8 | tmp[2] << 16 | tmp[3] << 24;
pnp_eisa_id_to_string(eisa_id, id);
- pnp_add_id(dev, id);
+
+ dev = pnp_alloc_dev(&isapnp_protocol, number, id);
+ if (!dev)
+ return NULL;
+
dev->regs = tmp[4];
dev->card = card;
if (size > 5)
dev->regs |= tmp[5] << 8;
- dev->protocol = &isapnp_protocol;
dev->capabilities |= PNP_CONFIGURABLE;
dev->capabilities |= PNP_READ;
dev->capabilities |= PNP_WRITE;
Index: work10/drivers/pnp/pnpacpi/core.c
===================================================================
--- work10.orig/drivers/pnp/pnpacpi/core.c 2008-04-25 11:14:46.000000000 -0600
+++ work10/drivers/pnp/pnpacpi/core.c 2008-04-25 11:14:49.000000000 -0600
@@ -152,7 +152,6 @@
{
acpi_handle temp = NULL;
acpi_status status;
- struct pnp_id *dev_id;
struct pnp_dev *dev;
status = acpi_get_handle(device->handle, "_CRS", &temp);
@@ -160,11 +159,10 @@
is_exclusive_device(device))
return 0;
- dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
- if (!dev) {
- pnp_err("Out of memory");
+ dev = pnp_alloc_dev(&pnpacpi_protocol, num, acpi_device_hid(device));
+ if (!dev)
return -ENOMEM;
- }
+
dev->data = device->handle;
/* .enabled means the device can decode the resources */
dev->active = device->status.enabled;
@@ -180,19 +178,11 @@
if (ACPI_SUCCESS(status))
dev->capabilities |= PNP_DISABLE;
- dev->protocol = &pnpacpi_protocol;
-
if (strlen(acpi_device_name(device)))
strncpy(dev->name, acpi_device_name(device), sizeof(dev->name));
else
strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name));
- dev->number = num;
-
- dev_id = pnp_add_id(dev, acpi_device_hid(device));
- if (!dev_id)
- goto err;
-
if (dev->active) {
/* parse allocated resource */
status = pnpacpi_parse_allocated_resource(device->handle,
@@ -230,9 +220,6 @@
num++;
return AE_OK;
-err:
- kfree(dev);
- return -EINVAL;
}
static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
Index: work10/drivers/pnp/pnpbios/core.c
===================================================================
--- work10.orig/drivers/pnp/pnpbios/core.c 2008-04-25 11:14:48.000000000 -0600
+++ work10/drivers/pnp/pnpbios/core.c 2008-04-25 11:14:49.000000000 -0600
@@ -318,7 +318,6 @@
{
struct list_head *pos;
struct pnp_dev *dev;
- struct pnp_id *dev_id;
char id[8];
/* check if the device is already added */
@@ -328,18 +327,11 @@
return -1;
}
- dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
- if (!dev)
- return -1;
-
pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id);
- dev_id = pnp_add_id(dev, id);
- if (!dev_id) {
- kfree(dev);
+ dev = pnp_alloc_dev(&pnpbios_protocol, node->handle, id);
+ if (!dev)
return -1;
- }
- dev->number = node->handle;
pnpbios_parse_data_stream(dev, node);
dev->active = pnp_is_active(dev);
dev->flags = node->flags;
@@ -352,7 +344,6 @@
dev->capabilities |= PNP_WRITE;
if (dev->flags & PNPBIOS_REMOVABLE)
dev->capabilities |= PNP_REMOVABLE;
- dev->protocol = &pnpbios_protocol;
/* clear out the damaged flags */
if (!dev->active)
--
next prev parent reply other threads:[~2008-04-25 18:39 UTC|newest]
Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-25 18:38 [patch 00/54] PNP cleanup, v4 Bjorn Helgaas
2008-04-25 18:38 ` [patch 01/54] PNP: turn on -DDEBUG when CONFIG_PNP_DEBUG is set Bjorn Helgaas
2008-04-25 18:38 ` [patch 02/54] ISAPNP: move config register addresses out of isapnp.h Bjorn Helgaas
2008-04-25 18:38 ` [patch 03/54] PNPACPI: continue after _CRS and _PRS errors Bjorn Helgaas
2008-04-25 18:38 ` [patch 04/54] PNP: make pnp_add_id() internal to PNP core Bjorn Helgaas
2008-04-25 18:38 ` [patch 05/54] PNP: change pnp_add_id() to allocate its own pnp_id structures Bjorn Helgaas
2008-04-25 18:38 ` [patch 06/54] PNP: add pnp_eisa_id_to_string() Bjorn Helgaas
2008-04-25 18:38 ` Bjorn Helgaas [this message]
2008-04-25 18:38 ` [patch 08/54] PNP: make pnp_add_card_id() internal to PNP core Bjorn Helgaas
2008-04-25 18:38 ` [patch 09/54] PNP: change pnp_add_card_id() to allocate its own pnp_id structures Bjorn Helgaas
2008-04-25 18:38 ` [patch 10/54] ISAPNP: pull pnp_add_card_id() out of isapnp_parse_card_id() Bjorn Helgaas
2008-04-25 18:38 ` [patch 11/54] PNP: add pnp_alloc_card() Bjorn Helgaas
2008-04-25 18:38 ` [patch 12/54] PNPACPI: pnpacpi_encode_ext_irq() wrongly set "irq" instead of "extended_irq" Bjorn Helgaas
2008-04-25 18:38 ` [patch 13/54] PNPACPI: use temporaries to reduce repetition Bjorn Helgaas
2008-04-25 18:38 ` [patch 14/54] PNPACPI: hoist dma_flags() out of pnpacpi_parse_allocated_dmaresource() Bjorn Helgaas
2008-04-25 18:38 ` [patch 15/54] PNPACPI: extend irq_flags() to set IORESOURCE_IRQ_SHAREABLE when appropriate Bjorn Helgaas
2008-04-25 18:38 ` [patch 16/54] PNPACPI: pass pnp_dev instead of acpi_handle Bjorn Helgaas
2008-04-25 18:38 ` [patch 17/54] PNP: add debug output to option registration Bjorn Helgaas
2008-04-25 18:38 ` [patch 18/54] PNP: remove pnp_resource_table from internal get/set interfaces Bjorn Helgaas
2008-04-25 18:38 ` [patch 19/54] PNP: remove more pnp_resource_table arguments Bjorn Helgaas
2008-04-25 18:38 ` [patch 20/54] PNP: add debug output to encoders Bjorn Helgaas
2008-04-25 18:38 ` [patch 21/54] PNP: add debug when assigning PNP resources Bjorn Helgaas
2008-04-26 21:26 ` Rene Herman
2008-04-28 15:25 ` Bjorn Helgaas
2008-04-25 18:38 ` [patch 22/54] PNP: add pnp_init_resources(struct pnp_dev *) interface Bjorn Helgaas
2008-04-25 18:38 ` [patch 23/54] PNP: remove pnp_resource_table from internal pnp_clean_resource_table interface Bjorn Helgaas
2008-04-25 18:38 ` [patch 24/54] PNP: remove unused interfaces using pnp_resource_table Bjorn Helgaas
2008-04-25 18:38 ` [patch 25/54] PNP: use dev_printk when possible Bjorn Helgaas
2008-04-25 18:38 ` [patch 26/54] PNP: factor pnp_init_resource_table() and pnp_clean_resource_table() Bjorn Helgaas
2008-04-26 21:33 ` Rene Herman
2008-04-28 17:15 ` Bjorn Helgaas
2008-04-25 18:38 ` [patch 27/54] PNP: add pnp_get_resource() interface Bjorn Helgaas
2008-04-25 18:38 ` [patch 28/54] PNP: remove pnp_mem_flags() as an lvalue Bjorn Helgaas
2008-04-25 18:38 ` [patch 29/54] PNP: convert resource accessors to use pnp_get_resource(), not pnp_resource_table Bjorn Helgaas
2008-04-26 21:42 ` Rene Herman
2008-04-28 17:19 ` Bjorn Helgaas
2008-04-25 18:38 ` [patch 30/54] PNP: use conventional "i" for loop indices Bjorn Helgaas
2008-04-25 18:38 ` [patch 31/54] PNP: reduce redundancy in pnp_assign_port() and others Bjorn Helgaas
2008-04-25 18:38 ` [patch 32/54] PNP: reduce redundancy in pnp_check_port() " Bjorn Helgaas
2008-04-25 18:38 ` [patch 33/54] PNP: reduce redundancy in pnp_set_current_resources() Bjorn Helgaas
2008-04-25 18:38 ` [patch 34/54] PNP: check for conflicts with all resources, not just earlier ones Bjorn Helgaas
2008-04-25 18:38 ` [patch 35/54] PNP: pass resources, not indexes, to pnp_check_port(), et al Bjorn Helgaas
2008-04-25 18:38 ` [patch 36/54] PNP: convert resource checks to use pnp_get_resource(), not pnp_resource_table Bjorn Helgaas
2008-04-25 18:38 ` [patch 37/54] PNP: convert encoders " Bjorn Helgaas
2008-04-25 18:38 ` [patch 38/54] PNP: remove PNP_MAX_* uses Bjorn Helgaas
2008-04-26 22:10 ` Rene Herman
2008-04-25 18:38 ` [patch 39/54] rtc: dont reference pnp_resource_table directly Bjorn Helgaas
2008-04-25 18:38 ` [patch 40/54] PNP: make pnp_resource_table private to PNP core Bjorn Helgaas
2008-04-25 18:38 ` [patch 41/54] PNP: remove pnp_resource_table references from resource decoders Bjorn Helgaas
2008-04-26 22:28 ` Rene Herman
2008-04-28 20:36 ` Bjorn Helgaas
2008-04-28 20:41 ` Rene Herman
2008-04-25 18:38 ` [patch 42/54] PNP: add struct pnp_resource Bjorn Helgaas
2008-04-25 18:38 ` [patch 43/54] PNP: add pnp_resource index for ISAPNP Bjorn Helgaas
2008-04-25 18:38 ` [patch 44/54] PNP: add pnp_new_resource() to find a new unset pnp_resource Bjorn Helgaas
2008-04-26 22:37 ` Rene Herman
2008-04-28 20:43 ` Bjorn Helgaas
2008-04-25 18:38 ` [patch 45/54] PNP: make generic pnp_add_irq_resource() Bjorn Helgaas
2008-04-25 18:38 ` [patch 46/54] PNP: make generic pnp_add_dma_resource() Bjorn Helgaas
2008-04-25 18:38 ` [patch 47/54] PNP: make generic pnp_add_io_resource() Bjorn Helgaas
2008-04-25 18:38 ` [patch 48/54] PNP: make generic pnp_add_mem_resource() Bjorn Helgaas
2008-04-25 18:38 ` [patch 49/54] PNP: use pnp_get_pnp_resource() in resource assignment functions Bjorn Helgaas
2008-04-25 18:38 ` [patch 50/54] ISAPNP: fold isapnp_read_resources() back into isapnp_get_resources() Bjorn Helgaas
2008-04-26 23:07 ` Rene Herman
2008-04-28 21:07 ` Bjorn Helgaas
2008-04-29 6:53 ` 2.6.25 pci=noacpi Richard
2008-04-29 7:04 ` Andrew Morton
2008-04-29 7:17 ` Richard
2008-04-29 7:27 ` Richard
2008-04-29 11:01 ` Richard
2008-05-01 5:10 ` Len Brown
2008-05-01 7:09 ` Richard
2008-05-01 15:59 ` Len Brown
2008-05-02 11:23 ` Richard
2008-05-02 12:47 ` Andrew Morton
2008-05-02 13:11 ` Richard
2008-05-07 10:19 ` Thomas Renninger
2008-05-08 7:23 ` Richard
2008-05-08 11:06 ` Thomas Renninger
2008-05-08 11:38 ` Richard
2008-05-08 12:37 ` Thomas Renninger
2008-05-04 19:23 ` Rene Herman
2008-05-08 6:59 ` Richard
2008-05-08 7:08 ` Richard
2008-05-08 11:50 ` Rene Herman
2008-04-25 18:38 ` [patch 51/54] PNPACPI: move _CRS/_PRS warnings closer to the action Bjorn Helgaas
2008-04-25 18:38 ` [patch 52/54] PNP: make interfaces private to the PNP core Bjorn Helgaas
2008-04-25 18:39 ` [patch 53/54] ISAPNP: remove unused pnp_dev->regs field Bjorn Helgaas
2008-04-25 18:39 ` [patch 54/54] PNPBIOS: remove include/linux/pnpbios.h Bjorn Helgaas
2008-04-26 23:34 ` [patch 00/54] PNP cleanup, v4 Rene Herman
2008-04-26 23:47 ` Rene Herman
2008-04-28 21:16 ` Bjorn Helgaas
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=20080425183925.542039833@ldl.fc.hp.com \
--to=bjorn.helgaas@hp.com \
--cc=abelay@mit.edu \
--cc=akpm@linux-foundation.org \
--cc=ambx1@neo.rr.com \
--cc=castet.matthieu@free.fr \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=perex@perex.cz \
--cc=rene.herman@keyaccess.nl \
--cc=shaohua.li@intel.com \
--cc=trenn@suse.de \
/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