[PATCH] pcmcia/pcmcia_resource.c: fix crash when using Cardbus cards

Using the old ioctl interface together with cardbus card gives a NULL
pointer dereference since cardbus devices don't have a struct pcmcia_device.
also s->io[0].res can be NULL as well.

Fix is to move the pcmcia code after the cardbus code and to check for a null
pointer.

Signed-off-by: Daniel Ritz <daniel.ritz@gmx.ch>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>

authored by Daniel Ritz and committed by Dominik Brodowski 48b950ff daaeb72b

+11 -4
+11 -4
drivers/pcmcia/pcmcia_resource.c
··· 208 208 if (!(s->state & SOCKET_PRESENT)) 209 209 return CS_NO_CARD; 210 210 211 - config->Function = p_dev->func; 212 211 213 212 #ifdef CONFIG_CARDBUS 214 213 if (s->state & SOCKET_CARDBUS) { ··· 221 222 config->AssignedIRQ = s->irq.AssignedIRQ; 222 223 if (config->AssignedIRQ) 223 224 config->Attributes |= CONF_ENABLE_IRQ; 224 - config->BasePort1 = s->io[0].res->start; 225 - config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1; 225 + if (s->io[0].res) { 226 + config->BasePort1 = s->io[0].res->start; 227 + config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1; 228 + } 226 229 } 227 230 return CS_SUCCESS; 228 231 } 229 232 #endif 230 233 231 - c = (p_dev) ? p_dev->function_config : NULL; 234 + if (p_dev) { 235 + c = p_dev->function_config; 236 + config->Function = p_dev->func; 237 + } else { 238 + c = NULL; 239 + config->Function = 0; 240 + } 232 241 233 242 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) { 234 243 config->Attributes = 0;