stuff-up in pcmcia/cardbus stuff
Recent 2.5 kernels will crash with a null pointer dereference on my powerbook (PowerPC laptop) when I try to suspend. I tracked it down to cardbus_suspend() in drivers/pcmcia/pci-socket.c calling pcmcia_suspend_socket() with a NULL argument. It turns out that socket->pcmcia_socket is never set in the current code.
This changeset seems to be the culprit:
ChangeSet 1.1017 2003/02/15 12:42:51 [email protected]
[PATCH] pcmcia: use device_class->add_device/remove_device
This patch removes the {un}register_ss_entry/pcmcia_{un}register_socket calls, and replaces them with generic driver-model-compatible functions.
Also, update the CodingStyle of these cs.c functions to what's recommended in the Linux kernel.
Paul.
Quoted 5 lines · Paul Mackerras
Recent 2.5 kernels will crash with a null pointer dereference on my powerbook (PowerPC laptop) when I try to suspend. I tracked it down to
cardbus_suspend()indrivers/pcmcia/pci-socket.ccallingpcmcia_suspend_socket()with a NULL argument. It turns out thatsocket->pcmcia_socketis never set in the current code.
Indeed. socket->pcmcia_socket (old) == socket->cls_d.s_info[0] (new) Could you please check whether this patch helps?
Dominik
drivers/pcmcia/pci_socket.c +4 -2
@@ -230,14 +230,16 @@static int cardbus_suspend (struct pci_dev *dev,u32 state) {pci_socket_t *socket =pci_get_drvdata (dev); -pcmcia_suspend_socket (socket->pcmcia_socket); +if (socket && socket->cls_d.s_info[0 ]) +pcmcia_suspend_socket (socket->cls_d.s_info[0 ]);return 0 ; }static int cardbus_resume (struct pci_dev *dev) {pci_socket_t *socket =pci_get_drvdata (dev); -pcmcia_resume_socket (socket->pcmcia_socket); +if (socket && socket->cls_d.s_info[0 ]) +pcmcia_resume_socket (socket->cls_d.s_info[0 ]);return 0 ; }
drivers/pcmcia/pci_socket.h +0 -1
@@ -20,7 +20,6 @@socket_cap_t cap;spinlock_t event_lock;unsigned int events; -struct socket_info_t *pcmcia_socket;struct work_struct tq_task;struct timer_list poll_timer;
Quoted 1 line · Dominik Brodowski
Indeed.
socket->pcmcia_socket(old) == socket->cls_d.s_info[0] (new)
If this is true...
Quoted 8 lines
drivers/pcmcia/pci_socket.c +2
-1@@ -230,14 +230,16 @@static int cardbus_suspend (struct pci_dev *dev,u32 state) {pci_socket_t *socket =pci_get_drvdata (dev); -pcmcia_suspend_socket (socket->pcmcia_socket); +if (socket && socket->cls_d.s_info[0 ]) +pcmcia_suspend_socket (socket->cls_d.s_info[0 ]);return 0 ;
drivers/pcmcia/pci_socket.c line 244
Quoted 10 lines
drivers/pcmcia/pci_socket.c +2
-1}static int cardbus_resume (struct pci_dev *dev) {pci_socket_t *socket =pci_get_drvdata (dev); -pcmcia_resume_socket (socket->pcmcia_socket); +if (socket && socket->cls_d.s_info[0 ]) +pcmcia_resume_socket (socket->cls_d.s_info[0 ]);return 0 ; }
1) ...why do you bother checking for NULL? Isn't NULL indicative of a BUG(), instead?
2) why are multiple s_info records allocated, when you hardcode use of record #0 ?
Jeff
Quoted 15 lines · Jeff Garzik
Quoted 1 line · Dominik Brodowski
Indeed.
socket->pcmcia_socket(old) == socket->cls_d.s_info[0] (new)If this is true...
Quoted 10 lines
drivers/pcmcia/pci_socket.c +2
-1@@ -230,14 +230,16 @@static int cardbus_suspend (struct pci_dev *dev,u32 state) {pci_socket_t *socket =pci_get_drvdata (dev); -pcmcia_suspend_socket (socket->pcmcia_socket); +if (socket && socket->cls_d.s_info[0 ]) +pcmcia_suspend_socket (socket->cls_d.s_info[0 ]);return 0 ; }
Quoted 12 lines
drivers/pcmcia/pci_socket.c line 244
Quoted 8 lines
drivers/pcmcia/pci_socket.c +2
-1static int cardbus_resume (struct pci_dev *dev) {pci_socket_t *socket =pci_get_drvdata (dev); -pcmcia_resume_socket (socket->pcmcia_socket); +if (socket && socket->cls_d.s_info[0 ]) +pcmcia_resume_socket (socket->cls_d.s_info[0 ]);return 0 ; }1) ...why do you bother checking for NULL? Isn't NULL indicative of a
BUG(), instead?
Well, it's only a safeguard against suspending / resuming combined with probing or removing the device. Else it's a BUG indeed...
Quoted 2 lines
2) why are multiple
s_inforecords allocated, when you hardcode use of record #0 ?
Only one s_info is actually allocated (in cs.c::pcmcia_register_socket) as only one pcmcia/cardbus socket is attached to one pci_dev for yenta-style devices. There are up to four pcmcia sockets to one pci_dev for i82092 devices, though. And so s_info[3] might be perfectly valid within the i82092 driver.
Dominik
Quoted 4 lines · Jeff Garzik
Quoted 1 line · Dominik Brodowski
Indeed.
socket->pcmcia_socket(old) == socket->cls_d.s_info[0] (new)If this is true...
<snip>
Quoted 3 lines
2) why are multiple
s_inforecords allocated, when you hardcode use of record #0 ?
Indeed, the allocation of MAX_SOCK_PER_DEV s_info[] pointers is pointless.
Dominik
drivers/pcmcia/cs.c +2 -1
@@ -330,11 +330,12 @@return -ENOMEM ;memset (s_info,0 , cls_d->nsock *sizeof (socket_info_t)); + cls_d->s_info = s_info; +/* socket initialization */ for (i =0 ; i < cls_d->nsock; i++) {socket_info_t *s = &s_info[i]; - cls_d->s_info[i] = s; s->ss_entry = cls_d->ops; s->sock = i;
drivers/pcmcia/pci_socket.c +4 -2
@@ -230,14 +230,16 @@static int cardbus_suspend (struct pci_dev *dev,u32 state) {pci_socket_t *socket =pci_get_drvdata (dev); -pcmcia_suspend_socket (socket->pcmcia_socket); +if (socket && socket->cls_d.s_info) +pcmcia_suspend_socket (socket->cls_d.s_info);return 0 ; }static int cardbus_resume (struct pci_dev *dev) {pci_socket_t *socket =pci_get_drvdata (dev); -pcmcia_resume_socket (socket->pcmcia_socket); +if (socket && socket->cls_d.s_info) +pcmcia_resume_socket (socket->cls_d.s_info);return 0 ; }
drivers/pcmcia/pci_socket.h +0 -1
@@ -20,7 +20,6 @@socket_cap_t cap;spinlock_t event_lock;unsigned int events; -struct socket_info_t *pcmcia_socket;struct work_struct tq_task;struct timer_list poll_timer;
include/pcmcia/ss.h +1 -3
@@ -144,12 +144,10 @@* Calls to set up low-level "Socket Services" drivers */ -#define MAX_SOCKETS_PER_DEV 8 -struct pcmcia_socket_class_data {unsigned int nsock;/* number of sockets */ struct pccard_operations *ops;/* see above */ -void *s_info[MAX_SOCKETS_PER_DEV ];/* socket_info_t */ +void *s_info;/* socket_info_t */ unsigned int use_bus_pm; };