From 93e4d69400fdfd721616200fe27809ce139fd734 Mon Sep 17 00:00:00 2001 From: Lukas Bulwahn Date: Mon, 16 Aug 2021 17:01:15 +0200 Subject: pcmcia: clean up dead drivers for CompuLab CM-X255/CM-X270 boards Commit 9d3239147d6d ("ARM: pxa: remove Compulab pxa2xx boards") removes the config MACH_ARMCORE in ./arch/arm/mach-pxa/Kconfig. Hence, ./scripts/checkkconfigsymbols.py warns on non-existing configs: MACH_ARMCORE Referencing files: drivers/pcmcia/Kconfig, drivers/pcmcia/Makefile Clean up the dead remains of pcmcia drivers for Compulab pxa2xx boards. Signed-off-by: Lukas Bulwahn Signed-off-by: Dominik Brodowski --- drivers/pcmcia/Kconfig | 2 +- drivers/pcmcia/Makefile | 2 - drivers/pcmcia/pxa2xx_cm_x255.c | 124 ---------------------------------------- drivers/pcmcia/pxa2xx_cm_x270.c | 103 --------------------------------- drivers/pcmcia/pxa2xx_cm_x2xx.c | 44 -------------- 5 files changed, 1 insertion(+), 274 deletions(-) delete mode 100644 drivers/pcmcia/pxa2xx_cm_x255.c delete mode 100644 drivers/pcmcia/pxa2xx_cm_x270.c delete mode 100644 drivers/pcmcia/pxa2xx_cm_x2xx.c (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig index d13b8d1a780a..ab53eab635f6 100644 --- a/drivers/pcmcia/Kconfig +++ b/drivers/pcmcia/Kconfig @@ -209,7 +209,7 @@ config PCMCIA_PXA2XX tristate "PXA2xx support" depends on ARM && ARCH_PXA && PCMCIA depends on (ARCH_LUBBOCK || MACH_MAINSTONE || PXA_SHARPSL \ - || MACH_ARMCORE || ARCH_PXA_PALM || TRIZEPS_PCMCIA \ + || ARCH_PXA_PALM || TRIZEPS_PCMCIA \ || ARCOM_PCMCIA || ARCH_PXA_ESERIES || MACH_STARGATE2 \ || MACH_VPAC270 || MACH_BALLOON3 || MACH_COLIBRI \ || MACH_COLIBRI320 || MACH_H4700) diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile index d82c07c4806b..2d5657cfc49c 100644 --- a/drivers/pcmcia/Makefile +++ b/drivers/pcmcia/Makefile @@ -48,10 +48,8 @@ sa1100_cs-$(CONFIG_SA1100_H3100) += sa1100_h3600.o sa1100_cs-$(CONFIG_SA1100_H3600) += sa1100_h3600.o sa1100_cs-$(CONFIG_SA1100_SIMPAD) += sa1100_simpad.o -pxa2xx_cm_x2xx_cs-y += pxa2xx_cm_x2xx.o pxa2xx_cm_x255.o pxa2xx_cm_x270.o pxa2xx-obj-$(CONFIG_MACH_MAINSTONE) += pxa2xx_mainstone.o pxa2xx-obj-$(CONFIG_PXA_SHARPSL) += pxa2xx_sharpsl.o -pxa2xx-obj-$(CONFIG_MACH_ARMCORE) += pxa2xx_cm_x2xx_cs.o pxa2xx-obj-$(CONFIG_ARCOM_PCMCIA) += pxa2xx_viper.o pxa2xx-obj-$(CONFIG_TRIZEPS_PCMCIA) += pxa2xx_trizeps4.o pxa2xx-obj-$(CONFIG_MACH_PALMTX) += pxa2xx_palmtx.o diff --git a/drivers/pcmcia/pxa2xx_cm_x255.c b/drivers/pcmcia/pxa2xx_cm_x255.c deleted file mode 100644 index c0b6b846fbaa..000000000000 --- a/drivers/pcmcia/pxa2xx_cm_x255.c +++ /dev/null @@ -1,124 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * linux/drivers/pcmcia/pxa/pxa_cm_x255.c - * - * Compulab Ltd., 2003, 2007, 2008 - * Mike Rapoport - */ - -#include -#include -#include -#include -#include - -#include "soc_common.h" - -#define GPIO_PCMCIA_SKTSEL (54) -#define GPIO_PCMCIA_S0_CD_VALID (16) -#define GPIO_PCMCIA_S1_CD_VALID (17) -#define GPIO_PCMCIA_S0_RDYINT (6) -#define GPIO_PCMCIA_S1_RDYINT (8) -#define GPIO_PCMCIA_RESET (9) - -static int cmx255_pcmcia_hw_init(struct soc_pcmcia_socket *skt) -{ - int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset"); - if (ret) - return ret; - gpio_direction_output(GPIO_PCMCIA_RESET, 0); - - if (skt->nr == 0) { - skt->stat[SOC_STAT_CD].gpio = GPIO_PCMCIA_S0_CD_VALID; - skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD"; - skt->stat[SOC_STAT_RDY].gpio = GPIO_PCMCIA_S0_RDYINT; - skt->stat[SOC_STAT_RDY].name = "PCMCIA0 RDY"; - } else { - skt->stat[SOC_STAT_CD].gpio = GPIO_PCMCIA_S1_CD_VALID; - skt->stat[SOC_STAT_CD].name = "PCMCIA1 CD"; - skt->stat[SOC_STAT_RDY].gpio = GPIO_PCMCIA_S1_RDYINT; - skt->stat[SOC_STAT_RDY].name = "PCMCIA1 RDY"; - } - - return 0; -} - -static void cmx255_pcmcia_shutdown(struct soc_pcmcia_socket *skt) -{ - gpio_free(GPIO_PCMCIA_RESET); -} - - -static void cmx255_pcmcia_socket_state(struct soc_pcmcia_socket *skt, - struct pcmcia_state *state) -{ - state->vs_3v = 0; - state->vs_Xv = 0; -} - - -static int cmx255_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, - const socket_state_t *state) -{ - switch (skt->nr) { - case 0: - if (state->flags & SS_RESET) { - gpio_set_value(GPIO_PCMCIA_SKTSEL, 0); - udelay(1); - gpio_set_value(GPIO_PCMCIA_RESET, 1); - udelay(10); - gpio_set_value(GPIO_PCMCIA_RESET, 0); - } - break; - case 1: - if (state->flags & SS_RESET) { - gpio_set_value(GPIO_PCMCIA_SKTSEL, 1); - udelay(1); - gpio_set_value(GPIO_PCMCIA_RESET, 1); - udelay(10); - gpio_set_value(GPIO_PCMCIA_RESET, 0); - } - break; - } - - return 0; -} - -static struct pcmcia_low_level cmx255_pcmcia_ops __initdata = { - .owner = THIS_MODULE, - .hw_init = cmx255_pcmcia_hw_init, - .hw_shutdown = cmx255_pcmcia_shutdown, - .socket_state = cmx255_pcmcia_socket_state, - .configure_socket = cmx255_pcmcia_configure_socket, - .nr = 1, -}; - -static struct platform_device *cmx255_pcmcia_device; - -int __init cmx255_pcmcia_init(void) -{ - int ret; - - cmx255_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); - - if (!cmx255_pcmcia_device) - return -ENOMEM; - - ret = platform_device_add_data(cmx255_pcmcia_device, &cmx255_pcmcia_ops, - sizeof(cmx255_pcmcia_ops)); - - if (ret == 0) { - printk(KERN_INFO "Registering cm-x255 PCMCIA interface.\n"); - ret = platform_device_add(cmx255_pcmcia_device); - } - - if (ret) - platform_device_put(cmx255_pcmcia_device); - - return ret; -} - -void __exit cmx255_pcmcia_exit(void) -{ - platform_device_unregister(cmx255_pcmcia_device); -} diff --git a/drivers/pcmcia/pxa2xx_cm_x270.c b/drivers/pcmcia/pxa2xx_cm_x270.c deleted file mode 100644 index 36e35da5f887..000000000000 --- a/drivers/pcmcia/pxa2xx_cm_x270.c +++ /dev/null @@ -1,103 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * linux/drivers/pcmcia/pxa/pxa_cm_x270.c - * - * Compulab Ltd., 2003, 2007, 2008 - * Mike Rapoport - */ - -#include -#include -#include -#include -#include - -#include "soc_common.h" - -#define GPIO_PCMCIA_S0_CD_VALID (84) -#define GPIO_PCMCIA_S0_RDYINT (82) -#define GPIO_PCMCIA_RESET (53) - -static int cmx270_pcmcia_hw_init(struct soc_pcmcia_socket *skt) -{ - int ret = gpio_request(GPIO_PCMCIA_RESET, "PCCard reset"); - if (ret) - return ret; - gpio_direction_output(GPIO_PCMCIA_RESET, 0); - - skt->stat[SOC_STAT_CD].gpio = GPIO_PCMCIA_S0_CD_VALID; - skt->stat[SOC_STAT_CD].name = "PCMCIA0 CD"; - skt->stat[SOC_STAT_RDY].gpio = GPIO_PCMCIA_S0_RDYINT; - skt->stat[SOC_STAT_RDY].name = "PCMCIA0 RDY"; - - return ret; -} - -static void cmx270_pcmcia_shutdown(struct soc_pcmcia_socket *skt) -{ - gpio_free(GPIO_PCMCIA_RESET); -} - - -static void cmx270_pcmcia_socket_state(struct soc_pcmcia_socket *skt, - struct pcmcia_state *state) -{ - state->vs_3v = 0; - state->vs_Xv = 0; -} - - -static int cmx270_pcmcia_configure_socket(struct soc_pcmcia_socket *skt, - const socket_state_t *state) -{ - switch (skt->nr) { - case 0: - if (state->flags & SS_RESET) { - gpio_set_value(GPIO_PCMCIA_RESET, 1); - udelay(10); - gpio_set_value(GPIO_PCMCIA_RESET, 0); - } - break; - } - - return 0; -} - -static struct pcmcia_low_level cmx270_pcmcia_ops __initdata = { - .owner = THIS_MODULE, - .hw_init = cmx270_pcmcia_hw_init, - .hw_shutdown = cmx270_pcmcia_shutdown, - .socket_state = cmx270_pcmcia_socket_state, - .configure_socket = cmx270_pcmcia_configure_socket, - .nr = 1, -}; - -static struct platform_device *cmx270_pcmcia_device; - -int __init cmx270_pcmcia_init(void) -{ - int ret; - - cmx270_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); - - if (!cmx270_pcmcia_device) - return -ENOMEM; - - ret = platform_device_add_data(cmx270_pcmcia_device, &cmx270_pcmcia_ops, - sizeof(cmx270_pcmcia_ops)); - - if (ret == 0) { - printk(KERN_INFO "Registering cm-x270 PCMCIA interface.\n"); - ret = platform_device_add(cmx270_pcmcia_device); - } - - if (ret) - platform_device_put(cmx270_pcmcia_device); - - return ret; -} - -void __exit cmx270_pcmcia_exit(void) -{ - platform_device_unregister(cmx270_pcmcia_device); -} diff --git a/drivers/pcmcia/pxa2xx_cm_x2xx.c b/drivers/pcmcia/pxa2xx_cm_x2xx.c deleted file mode 100644 index 14eae238131d..000000000000 --- a/drivers/pcmcia/pxa2xx_cm_x2xx.c +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * linux/drivers/pcmcia/pxa/pxa_cm_x2xx.c - * - * Compulab Ltd., 2003, 2007, 2008 - * Mike Rapoport - */ - -#include - -#include -#include - -int cmx255_pcmcia_init(void); -int cmx270_pcmcia_init(void); -void cmx255_pcmcia_exit(void); -void cmx270_pcmcia_exit(void); - -static int __init cmx2xx_pcmcia_init(void) -{ - int ret = -ENODEV; - - if (machine_is_armcore() && cpu_is_pxa25x()) - ret = cmx255_pcmcia_init(); - else if (machine_is_armcore() && cpu_is_pxa27x()) - ret = cmx270_pcmcia_init(); - - return ret; -} - -static void __exit cmx2xx_pcmcia_exit(void) -{ - if (machine_is_armcore() && cpu_is_pxa25x()) - cmx255_pcmcia_exit(); - else if (machine_is_armcore() && cpu_is_pxa27x()) - cmx270_pcmcia_exit(); -} - -module_init(cmx2xx_pcmcia_init); -module_exit(cmx2xx_pcmcia_exit); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Mike Rapoport "); -MODULE_DESCRIPTION("CM-x2xx PCMCIA driver"); -- cgit v1.2.3 From 3daaf2c7aae8f16845a59b57d3ae92e3d0965d21 Mon Sep 17 00:00:00 2001 From: Cai Huoqing Date: Sat, 28 Aug 2021 17:00:11 +0800 Subject: pcmcia: Make use of the helper macro SET_NOIRQ_SYSTEM_SLEEP_PM_OPS() Use the helper macro SET_NOIRQ_SYSTEM_SLEEP_PM_OPS() instead of the verbose operators ".suspend_noirq /.resume_noirq/.freeze_noirq/ .thaw_noirq/.poweroff_noirq/.restore_noirq", because the SET_NOIRQ_SYSTEM_SLEEP_PM_OPS() is a nice helper macro that could be brought in to make code a little clearer, a little more concise. Signed-off-by: Cai Huoqing Signed-off-by: Dominik Brodowski --- drivers/pcmcia/yenta_socket.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index 84bfc0e85d6b..e472da29d401 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c @@ -1342,12 +1342,7 @@ static int yenta_dev_resume_noirq(struct device *dev) } static const struct dev_pm_ops yenta_pm_ops = { - .suspend_noirq = yenta_dev_suspend_noirq, - .resume_noirq = yenta_dev_resume_noirq, - .freeze_noirq = yenta_dev_suspend_noirq, - .thaw_noirq = yenta_dev_resume_noirq, - .poweroff_noirq = yenta_dev_suspend_noirq, - .restore_noirq = yenta_dev_resume_noirq, + SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(yenta_dev_suspend_noirq, yenta_dev_resume_noirq) }; #define YENTA_PM_OPS (¥ta_pm_ops) -- cgit v1.2.3 From 468c14d82c931073b759e03e421788f5dbb9ad45 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 2 Jan 2022 18:39:12 +0100 Subject: pcmcia: comment out unused exca_readw() function The exca_readw() function is currently unused; therefore, comment it out. Reported-by: kernel test robot Signed-off-by: Dominik Brodowski --- drivers/pcmcia/yenta_socket.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index e472da29d401..e7ec3ea23db9 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c @@ -144,6 +144,7 @@ static inline u8 exca_readb(struct yenta_socket *socket, unsigned reg) return val; } +/* static inline u8 exca_readw(struct yenta_socket *socket, unsigned reg) { u16 val; @@ -152,6 +153,7 @@ static inline u8 exca_readw(struct yenta_socket *socket, unsigned reg) debug("%04x %04x\n", socket, reg, val); return val; } +*/ static inline void exca_writeb(struct yenta_socket *socket, unsigned reg, u8 val) { -- cgit v1.2.3 From ca0fe0d7c35c97528bdf621fdca75f13157c27af Mon Sep 17 00:00:00 2001 From: Zhou Qingyang Date: Wed, 1 Dec 2021 00:59:23 +0800 Subject: pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in __nonstatic_find_io_region() In __nonstatic_find_io_region(), pcmcia_make_resource() is assigned to res and used in pci_bus_alloc_resource(). There is a dereference of res in pci_bus_alloc_resource(), which could lead to a NULL pointer dereference on failure of pcmcia_make_resource(). Fix this bug by adding a check of res. This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs. Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug. Builds with CONFIG_PCCARD_NONSTATIC=y show no new warnings, and our static analyzer no longer warns about this code. Fixes: 49b1153adfe1 ("pcmcia: move all pcmcia_resource_ops providers into one module") Signed-off-by: Zhou Qingyang [linux@dominikbrodowski.net: Fix typo in commit message] Signed-off-by: Dominik Brodowski --- drivers/pcmcia/rsrc_nonstatic.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index bb15a8bdbaab..827ca6e9ee54 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -690,6 +690,9 @@ static struct resource *__nonstatic_find_io_region(struct pcmcia_socket *s, unsigned long min = base; int ret; + if (!res) + return NULL; + data.mask = align - 1; data.offset = base & data.mask; data.map = &s_data->io_db; -- cgit v1.2.3 From 977d2e7c63c3d04d07ba340b39987742e3241554 Mon Sep 17 00:00:00 2001 From: Zhou Qingyang Date: Wed, 1 Dec 2021 02:11:40 +0800 Subject: pcmcia: rsrc_nonstatic: Fix a NULL pointer dereference in nonstatic_find_mem_region() In nonstatic_find_mem_region(), pcmcia_make_resource() is assigned to res and used in pci_bus_alloc_resource(). There a dereference of res in pci_bus_alloc_resource(), which could lead to a NULL pointer dereference on failure of pcmcia_make_resource(). Fix this bug by adding a check of res. This bug was found by a static analyzer. The analysis employs differential checking to identify inconsistent security operations (e.g., checks or kfrees) between two code paths and confirms that the inconsistent operations are not recovered in the current function or the callers, so they constitute bugs. Note that, as a bug found by static analysis, it can be a false positive or hard to trigger. Multiple researchers have cross-reviewed the bug. Builds with CONFIG_PCCARD_NONSTATIC=y show no new warnings, and our static analyzer no longer warns about this code. Fixes: 49b1153adfe1 ("pcmcia: move all pcmcia_resource_ops providers into one module") Signed-off-by: Zhou Qingyang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/rsrc_nonstatic.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 827ca6e9ee54..1cac52870711 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -812,6 +812,9 @@ static struct resource *nonstatic_find_mem_region(u_long base, u_long num, unsigned long min, max; int ret, i, j; + if (!res) + return NULL; + low = low || !(s->features & SS_CAP_PAGE_REGS); data.mask = align - 1; -- cgit v1.2.3 From fffbcee9335ccf97adf2b5b342099b6430e8dbfd Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 2 Jan 2022 18:48:58 +0100 Subject: pcmcia: make pcmcia_release_io() void, as no-one is interested in return value As the only user of pcmcia_release_io() is not interested in its return value, and we cannot do anything on failure, convert the function to return void. Reported-by: Jason Wang Signed-off-by: Dominik Brodowski --- drivers/pcmcia/pcmcia_resource.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c index c1c197292111..d78091e79a0f 100644 --- a/drivers/pcmcia/pcmcia_resource.c +++ b/drivers/pcmcia/pcmcia_resource.c @@ -390,10 +390,9 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev) * "stale", we don't bother checking the port ranges against the * current socket values. */ -static int pcmcia_release_io(struct pcmcia_device *p_dev) +static void pcmcia_release_io(struct pcmcia_device *p_dev) { struct pcmcia_socket *s = p_dev->socket; - int ret = -EINVAL; config_t *c; mutex_lock(&s->ops_mutex); @@ -412,8 +411,6 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev) out: mutex_unlock(&s->ops_mutex); - - return ret; } /* pcmcia_release_io */ -- cgit v1.2.3 From 78e0185c25af8d1e20d3bb390c6c1e6b69ae3a52 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Fri, 15 Oct 2021 09:13:23 +0200 Subject: pcmcia: use sysfs_emit{,_at} for sysfs output Convert the PCMCIA core and yenta_socket.c to use sysfs_emit or sysfs_emit_at when providing output in sysfs. Signed-off-by: Dominik Brodowski --- drivers/pcmcia/ds.c | 20 +++++++++----------- drivers/pcmcia/rsrc_nonstatic.c | 6 +++--- drivers/pcmcia/socket_sysfs.c | 18 +++++++++--------- drivers/pcmcia/yenta_socket.c | 14 +++++++------- 4 files changed, 28 insertions(+), 30 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c index 5bd1b80424e7..ace133b9f7d4 100644 --- a/drivers/pcmcia/ds.c +++ b/drivers/pcmcia/ds.c @@ -998,7 +998,7 @@ static int runtime_resume(struct device *dev) static ssize_t field##_show (struct device *dev, struct device_attribute *attr, char *buf) \ { \ struct pcmcia_device *p_dev = to_pcmcia_dev(dev); \ - return p_dev->test ? sprintf(buf, format, p_dev->field) : -ENODEV; \ + return p_dev->test ? sysfs_emit(buf, format, p_dev->field) : -ENODEV; \ } \ static DEVICE_ATTR_RO(field); @@ -1006,7 +1006,7 @@ static DEVICE_ATTR_RO(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; \ + return p_dev->field ? sysfs_emit(buf, "%s\n", p_dev->field) : -ENODEV; \ } \ static DEVICE_ATTR_RO(name); @@ -1022,7 +1022,7 @@ 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; + return p_dev->socket ? sysfs_emit(buf, "0x%02x\n", p_dev->func) : -ENODEV; } static DEVICE_ATTR_RO(function); @@ -1030,13 +1030,12 @@ 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; - int i; + int i, at = 0; for (i = 0; i < PCMCIA_NUM_RESOURCES; i++) - str += sprintf(str, "%pr\n", p_dev->resource[i]); + at += sysfs_emit_at(buf, at, "%pr\n", p_dev->resource[i]); - return str - buf; + return at; } static DEVICE_ATTR_RO(resources); @@ -1045,9 +1044,9 @@ static ssize_t pm_state_show(struct device *dev, struct device_attribute *attr, struct pcmcia_device *p_dev = to_pcmcia_dev(dev); if (p_dev->suspended) - return sprintf(buf, "off\n"); + return sysfs_emit(buf, "off\n"); else - return sprintf(buf, "on\n"); + return sysfs_emit(buf, "on\n"); } static ssize_t pm_state_store(struct device *dev, struct device_attribute *attr, @@ -1081,8 +1080,7 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, hash[i] = crc32(0, p_dev->prod_id[i], strlen(p_dev->prod_id[i])); } - return sprintf(buf, "pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02X" - "pa%08Xpb%08Xpc%08Xpd%08X\n", + return sysfs_emit(buf, "pcmcia:m%04Xc%04Xf%02Xfn%02Xpfn%02Xpa%08Xpb%08Xpc%08Xpd%08X\n", p_dev->has_manf_id ? p_dev->manf_id : 0, p_dev->has_card_id ? p_dev->card_id : 0, p_dev->has_func_id ? p_dev->func_id : 0, diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c index 1cac52870711..6b6c578b5f92 100644 --- a/drivers/pcmcia/rsrc_nonstatic.c +++ b/drivers/pcmcia/rsrc_nonstatic.c @@ -1082,7 +1082,7 @@ static ssize_t show_io_db(struct device *dev, for (p = data->io_db.next; p != &data->io_db; p = p->next) { if (ret > (PAGE_SIZE - 10)) continue; - ret += scnprintf(&buf[ret], (PAGE_SIZE - ret - 1), + ret += sysfs_emit_at(buf, ret, "0x%08lx - 0x%08lx\n", ((unsigned long) p->base), ((unsigned long) p->base + p->num - 1)); @@ -1139,7 +1139,7 @@ static ssize_t show_mem_db(struct device *dev, p = p->next) { if (ret > (PAGE_SIZE - 10)) continue; - ret += scnprintf(&buf[ret], (PAGE_SIZE - ret - 1), + ret += sysfs_emit_at(buf, ret, "0x%08lx - 0x%08lx\n", ((unsigned long) p->base), ((unsigned long) p->base + p->num - 1)); @@ -1148,7 +1148,7 @@ static ssize_t show_mem_db(struct device *dev, for (p = data->mem_db.next; p != &data->mem_db; p = p->next) { if (ret > (PAGE_SIZE - 10)) continue; - ret += scnprintf(&buf[ret], (PAGE_SIZE - ret - 1), + ret += sysfs_emit_at(buf, ret, "0x%08lx - 0x%08lx\n", ((unsigned long) p->base), ((unsigned long) p->base + p->num - 1)); diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c index d1b220a1e1ab..c7a906664c36 100644 --- a/drivers/pcmcia/socket_sysfs.c +++ b/drivers/pcmcia/socket_sysfs.c @@ -38,8 +38,8 @@ static ssize_t pccard_show_type(struct device *dev, struct device_attribute *att if (!(s->state & SOCKET_PRESENT)) return -ENODEV; if (s->state & SOCKET_CARDBUS) - return sprintf(buf, "32-bit\n"); - return sprintf(buf, "16-bit\n"); + return sysfs_emit(buf, "32-bit\n"); + return sysfs_emit(buf, "16-bit\n"); } static DEVICE_ATTR(card_type, 0444, pccard_show_type, NULL); @@ -51,9 +51,9 @@ static ssize_t pccard_show_voltage(struct device *dev, struct device_attribute * if (!(s->state & SOCKET_PRESENT)) return -ENODEV; if (s->socket.Vcc) - return sprintf(buf, "%d.%dV\n", s->socket.Vcc / 10, + return sysfs_emit(buf, "%d.%dV\n", s->socket.Vcc / 10, s->socket.Vcc % 10); - return sprintf(buf, "X.XV\n"); + return sysfs_emit(buf, "X.XV\n"); } static DEVICE_ATTR(card_voltage, 0444, pccard_show_voltage, NULL); @@ -63,7 +63,7 @@ static ssize_t pccard_show_vpp(struct device *dev, struct device_attribute *attr struct pcmcia_socket *s = to_socket(dev); if (!(s->state & SOCKET_PRESENT)) return -ENODEV; - return sprintf(buf, "%d.%dV\n", s->socket.Vpp / 10, s->socket.Vpp % 10); + return sysfs_emit(buf, "%d.%dV\n", s->socket.Vpp / 10, s->socket.Vpp % 10); } static DEVICE_ATTR(card_vpp, 0444, pccard_show_vpp, NULL); @@ -73,7 +73,7 @@ static ssize_t pccard_show_vcc(struct device *dev, struct device_attribute *attr struct pcmcia_socket *s = to_socket(dev); if (!(s->state & SOCKET_PRESENT)) return -ENODEV; - return sprintf(buf, "%d.%dV\n", s->socket.Vcc / 10, s->socket.Vcc % 10); + return sysfs_emit(buf, "%d.%dV\n", s->socket.Vcc / 10, s->socket.Vcc % 10); } static DEVICE_ATTR(card_vcc, 0444, pccard_show_vcc, NULL); @@ -98,7 +98,7 @@ static ssize_t pccard_show_card_pm_state(struct device *dev, char *buf) { struct pcmcia_socket *s = to_socket(dev); - return sprintf(buf, "%s\n", s->state & SOCKET_SUSPEND ? "off" : "on"); + return sysfs_emit(buf, "%s\n", s->state & SOCKET_SUSPEND ? "off" : "on"); } static ssize_t pccard_store_card_pm_state(struct device *dev, @@ -145,7 +145,7 @@ static ssize_t pccard_show_irq_mask(struct device *dev, char *buf) { struct pcmcia_socket *s = to_socket(dev); - return sprintf(buf, "0x%04x\n", s->irq_mask); + return sysfs_emit(buf, "0x%04x\n", s->irq_mask); } static ssize_t pccard_store_irq_mask(struct device *dev, @@ -177,7 +177,7 @@ static ssize_t pccard_show_resource(struct device *dev, struct device_attribute *attr, char *buf) { struct pcmcia_socket *s = to_socket(dev); - return sprintf(buf, "%s\n", s->resource_setup_done ? "yes" : "no"); + return sysfs_emit(buf, "%s\n", s->resource_setup_done ? "yes" : "no"); } static ssize_t pccard_store_resource(struct device *dev, diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c index e7ec3ea23db9..837877daed62 100644 --- a/drivers/pcmcia/yenta_socket.c +++ b/drivers/pcmcia/yenta_socket.c @@ -178,16 +178,16 @@ static ssize_t show_yenta_registers(struct device *yentadev, struct device_attri struct yenta_socket *socket = dev_get_drvdata(yentadev); int offset = 0, i; - offset = snprintf(buf, PAGE_SIZE, "CB registers:"); + offset = sysfs_emit(buf, "CB registers:"); for (i = 0; i < 0x24; i += 4) { unsigned val; if (!(i & 15)) - offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i); + offset += sysfs_emit_at(buf, offset, "\n%02x:", i); val = cb_readl(socket, i); - offset += scnprintf(buf + offset, PAGE_SIZE - offset, " %08x", val); + offset += sysfs_emit_at(buf, offset, " %08x", val); } - offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n\nExCA registers:"); + offset += sysfs_emit_at(buf, offset, "\n\nExCA registers:"); for (i = 0; i < 0x45; i++) { unsigned char val; if (!(i & 7)) { @@ -195,12 +195,12 @@ static ssize_t show_yenta_registers(struct device *yentadev, struct device_attri memcpy(buf + offset, " -", 2); offset += 2; } else - offset += scnprintf(buf + offset, PAGE_SIZE - offset, "\n%02x:", i); + offset += sysfs_emit_at(buf, offset, "\n%02x:", i); } val = exca_readb(socket, i); - offset += scnprintf(buf + offset, PAGE_SIZE - offset, " %02x", val); + offset += sysfs_emit_at(buf, offset, " %02x", val); } - buf[offset++] = '\n'; + sysfs_emit_at(buf, offset, "\n"); return offset; } -- cgit v1.2.3 From fbb3485f1f931102d8ba606f1c28123f5b48afa3 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Sun, 9 Jan 2022 10:02:51 +0100 Subject: pcmcia: fix setting of kthread task states We need to set TASK_INTERRUPTIBLE before calling kthread_should_stop(). Otherwise, kthread_stop() might see that the pccardd thread is still in TASK_RUNNING state and fail to wake it up. Additionally, we only need to set the state back to TASK_RUNNING if kthread_should_stop() breaks the loop. Cc: Greg Kroah-Hartman Reported-by: Al Viro Reviewed-by: Matthew Wilcox (Oracle) Fixes: d3046ba809ce ("pcmcia: fix a boot time warning in pcmcia cs code") Signed-off-by: Dominik Brodowski --- drivers/pcmcia/cs.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'drivers/pcmcia') diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c index e211e2619680..f70197154a36 100644 --- a/drivers/pcmcia/cs.c +++ b/drivers/pcmcia/cs.c @@ -666,18 +666,16 @@ static int pccardd(void *__skt) if (events || sysfs_events) continue; + set_current_state(TASK_INTERRUPTIBLE); if (kthread_should_stop()) break; - set_current_state(TASK_INTERRUPTIBLE); - schedule(); - /* make sure we are running */ - __set_current_state(TASK_RUNNING); - try_to_freeze(); } + /* make sure we are running before we exit */ + __set_current_state(TASK_RUNNING); /* shut down socket, if a device is still present */ if (skt->state & SOCKET_PRESENT) { -- cgit v1.2.3