--- zzzz-none-000/linux-3.10.107/drivers/pcmcia/ds.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/pcmcia/ds.c 2021-02-04 17:41:59.000000000 +0000 @@ -81,8 +81,8 @@ struct pcmcia_dynid { - struct list_head node; - struct pcmcia_device_id id; + struct list_head node; + struct pcmcia_device_id id; }; /** @@ -284,8 +284,8 @@ dev_dbg(dev, "base %x, regs %x", p_dev->config_base, p_dev->config_regs); } else { - dev_printk(KERN_INFO, dev, - "pcmcia: could not parse base and rmask0 of CIS\n"); + dev_info(dev, + "pcmcia: could not parse base and rmask0 of CIS\n"); p_dev->config_base = 0; p_dev->config_regs = 0; } @@ -382,15 +382,15 @@ /* check for proper unloading */ if (p_dev->_irq || p_dev->_io || p_dev->_locked) - dev_printk(KERN_INFO, dev, - "pcmcia: driver %s did not release config properly\n", - p_drv->name); + dev_info(dev, + "pcmcia: driver %s did not release config properly\n", + p_drv->name); for (i = 0; i < MAX_WIN; i++) if (p_dev->_win & CLIENT_WIN_REQ(i)) - dev_printk(KERN_INFO, dev, - "pcmcia: driver %s did not release window properly\n", - p_drv->name); + dev_info(dev, + "pcmcia: driver %s did not release window properly\n", + p_drv->name); /* references from pcmcia_probe_device */ pcmcia_put_dev(p_dev); @@ -468,12 +468,10 @@ if ((length < 2) || (length > 255)) continue; - new = kmalloc(sizeof(char) * length, GFP_KERNEL); + new = kstrdup(tmp, GFP_KERNEL); if (!new) continue; - new = strncpy(new, tmp, length); - tmp = p_dev->prod_id[i]; p_dev->prod_id[i] = new; kfree(tmp); @@ -566,7 +564,7 @@ c->io[i].name = p_dev->devname; c->io[i].flags = IORESOURCE_IO; } - for (i = 0; i< MAX_WIN; i++) { + for (i = 0; i < MAX_WIN; i++) { c->mem[i].name = p_dev->devname; c->mem[i].flags = IORESOURCE_MEM; } @@ -578,8 +576,7 @@ mutex_unlock(&s->ops_mutex); - dev_printk(KERN_NOTICE, &p_dev->dev, - "pcmcia: registering new device %s (IRQ: %d)\n", + dev_notice(&p_dev->dev, "pcmcia: registering new device %s (IRQ: %d)\n", p_dev->devname, p_dev->irq); pcmcia_device_query(p_dev); @@ -634,8 +631,24 @@ ret = pccard_validate_cis(s, &no_chains); if (ret || !no_chains) { - dev_dbg(&s->dev, "invalid CIS or invalid resources\n"); - return -ENODEV; +#if defined(CONFIG_MTD_PCMCIA_ANONYMOUS) + /* Set up as an anonymous card. If we don't have anonymous + memory support then just error the card as there is no + point trying to second guess. + + Note: some cards have just a device entry, it may be + worth extending support to cover these in future */ + if (ret == -EIO) { + dev_info(&s->dev, "no CIS, assuming an anonymous memory card.\n"); + pcmcia_replace_cis(s, "\xFF", 1); + no_chains = 1; + ret = 0; + } else +#endif + { + dev_dbg(&s->dev, "invalid CIS or invalid resources\n"); + return -ENODEV; + } } if (!pccard_read_tuple(s, BIND_FN_ALL, CISTPL_LONGLINK_MFC, &mfc)) @@ -651,7 +664,7 @@ } -static int pcmcia_requery_callback(struct device *dev, void * _data) +static int pcmcia_requery_callback(struct device *dev, void *_data) { struct pcmcia_device *p_dev = to_pcmcia_dev(dev); if (!p_dev->dev.driver) { @@ -667,6 +680,9 @@ { int has_pfc; + if (!(s->state & SOCKET_PRESENT)) + return; + if (s->functions == 0) { pcmcia_card_add(s); return; @@ -726,7 +742,7 @@ * the one provided by the card is broken. The firmware files reside in * /lib/firmware/ in userspace. */ -static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename) +static int pcmcia_load_firmware(struct pcmcia_device *dev, char *filename) { struct pcmcia_socket *s = dev->socket; const struct firmware *fw; @@ -742,16 +758,14 @@ if (request_firmware(&fw, filename, &dev->dev) == 0) { if (fw->size >= CISTPL_MAX_CIS_SIZE) { ret = -EINVAL; - dev_printk(KERN_ERR, &dev->dev, - "pcmcia: CIS override is too big\n"); + dev_err(&dev->dev, "pcmcia: CIS override is too big\n"); goto release; } if (!pcmcia_replace_cis(s, fw->data, fw->size)) ret = 0; else { - dev_printk(KERN_ERR, &dev->dev, - "pcmcia: CIS override failed\n"); + dev_err(&dev->dev, "pcmcia: CIS override failed\n"); goto release; } @@ -778,7 +792,8 @@ #else /* !CONFIG_PCMCIA_LOAD_CIS */ -static inline int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename) +static inline int pcmcia_load_firmware(struct pcmcia_device *dev, + char *filename) { return -ENODEV; } @@ -992,16 +1007,17 @@ { \ struct pcmcia_device *p_dev = to_pcmcia_dev(dev); \ return p_dev->test ? sprintf(buf, format, p_dev->field) : -ENODEV; \ -} +} \ +static DEVICE_ATTR_RO(field); #define pcmcia_device_stringattr(name, field) \ static ssize_t name##_show (struct device *dev, struct device_attribute *attr, char *buf) \ { \ struct pcmcia_device *p_dev = to_pcmcia_dev(dev); \ return p_dev->field ? sprintf(buf, "%s\n", p_dev->field) : -ENODEV; \ -} +} \ +static DEVICE_ATTR_RO(name); -pcmcia_device_attr(func, socket, "0x%02x\n"); pcmcia_device_attr(func_id, has_func_id, "0x%02x\n"); pcmcia_device_attr(manf_id, has_manf_id, "0x%04x\n"); pcmcia_device_attr(card_id, has_card_id, "0x%04x\n"); @@ -1010,8 +1026,16 @@ pcmcia_device_stringattr(prod_id3, prod_id[2]); pcmcia_device_stringattr(prod_id4, prod_id[3]); -static ssize_t pcmcia_show_resources(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t function_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct pcmcia_device *p_dev = to_pcmcia_dev(dev); + return p_dev->socket ? sprintf(buf, "0x%02x\n", p_dev->func) : -ENODEV; +} +static DEVICE_ATTR_RO(function); + +static ssize_t resources_show(struct device *dev, + struct device_attribute *attr, char *buf) { struct pcmcia_device *p_dev = to_pcmcia_dev(dev); char *str = buf; @@ -1022,8 +1046,9 @@ return str - buf; } +static DEVICE_ATTR_RO(resources); -static ssize_t pcmcia_show_pm_state(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t pm_state_show(struct device *dev, struct device_attribute *attr, char *buf) { struct pcmcia_device *p_dev = to_pcmcia_dev(dev); @@ -1033,8 +1058,8 @@ return sprintf(buf, "on\n"); } -static ssize_t pcmcia_store_pm_state(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) +static ssize_t pm_state_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { struct pcmcia_device *p_dev = to_pcmcia_dev(dev); int ret = 0; @@ -1049,7 +1074,7 @@ return ret ? ret : count; } - +static DEVICE_ATTR_RW(pm_state); static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -1072,8 +1097,9 @@ p_dev->func, p_dev->device_no, hash[0], hash[1], hash[2], hash[3]); } +static DEVICE_ATTR_RO(modalias); -static ssize_t pcmcia_store_allow_func_id_match(struct device *dev, +static ssize_t allow_func_id_match_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct pcmcia_device *p_dev = to_pcmcia_dev(dev); @@ -1088,22 +1114,24 @@ return count; } +static DEVICE_ATTR_WO(allow_func_id_match); -static struct device_attribute pcmcia_dev_attrs[] = { - __ATTR(function, 0444, func_show, NULL), - __ATTR(pm_state, 0644, pcmcia_show_pm_state, pcmcia_store_pm_state), - __ATTR(resources, 0444, pcmcia_show_resources, NULL), - __ATTR_RO(func_id), - __ATTR_RO(manf_id), - __ATTR_RO(card_id), - __ATTR_RO(prod_id1), - __ATTR_RO(prod_id2), - __ATTR_RO(prod_id3), - __ATTR_RO(prod_id4), - __ATTR_RO(modalias), - __ATTR(allow_func_id_match, 0200, NULL, pcmcia_store_allow_func_id_match), - __ATTR_NULL, +static struct attribute *pcmcia_dev_attrs[] = { + &dev_attr_resources.attr, + &dev_attr_pm_state.attr, + &dev_attr_function.attr, + &dev_attr_func_id.attr, + &dev_attr_manf_id.attr, + &dev_attr_card_id.attr, + &dev_attr_prod_id1.attr, + &dev_attr_prod_id2.attr, + &dev_attr_prod_id3.attr, + &dev_attr_prod_id4.attr, + &dev_attr_modalias.attr, + &dev_attr_allow_func_id_match.attr, + NULL, }; +ATTRIBUTE_GROUPS(pcmcia_dev); /* PM support, also needed for reset */ @@ -1132,10 +1160,9 @@ if (p_drv->suspend) { ret = p_drv->suspend(p_dev); if (ret) { - dev_printk(KERN_ERR, dev, - "pcmcia: device %s (driver %s) did " - "not want to go to sleep (%d)\n", - p_dev->devname, p_drv->name, ret); + dev_err(dev, + "pcmcia: device %s (driver %s) did not want to go to sleep (%d)\n", + p_dev->devname, p_drv->name, ret); mutex_lock(&p_dev->socket->ops_mutex); p_dev->suspended = 0; mutex_unlock(&p_dev->socket->ops_mutex); @@ -1190,7 +1217,7 @@ } -static int pcmcia_bus_suspend_callback(struct device *dev, void * _data) +static int pcmcia_bus_suspend_callback(struct device *dev, void *_data) { struct pcmcia_socket *skt = _data; struct pcmcia_device *p_dev = to_pcmcia_dev(dev); @@ -1201,7 +1228,7 @@ return runtime_suspend(dev); } -static int pcmcia_bus_resume_callback(struct device *dev, void * _data) +static int pcmcia_bus_resume_callback(struct device *dev, void *_data) { struct pcmcia_socket *skt = _data; struct pcmcia_device *p_dev = to_pcmcia_dev(dev); @@ -1326,14 +1353,13 @@ socket = pcmcia_get_socket(socket); if (!socket) { - dev_printk(KERN_ERR, dev, - "PCMCIA obtaining reference to socket failed\n"); + dev_err(dev, "PCMCIA obtaining reference to socket failed\n"); return -ENODEV; } ret = sysfs_create_bin_file(&dev->kobj, &pccard_cis_attr); if (ret) { - dev_printk(KERN_ERR, dev, "PCMCIA registration failed\n"); + dev_err(dev, "PCMCIA registration failed\n"); pcmcia_put_socket(socket); return ret; } @@ -1345,7 +1371,7 @@ ret = pccard_register_pcmcia(socket, &pcmcia_bus_callback); if (ret) { - dev_printk(KERN_ERR, dev, "PCMCIA registration failed\n"); + dev_err(dev, "PCMCIA registration failed\n"); pcmcia_put_socket(socket); return ret; } @@ -1389,7 +1415,7 @@ .name = "pcmcia", .uevent = pcmcia_bus_uevent, .match = pcmcia_bus_match, - .dev_attrs = pcmcia_dev_attrs, + .dev_groups = pcmcia_dev_groups, .probe = pcmcia_device_probe, .remove = pcmcia_device_remove, .suspend = pcmcia_dev_suspend,