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