From 4f8d66a9fb2edcd05c1e563456a55a08910bfb37 Mon Sep 17 00:00:00 2001 From: Christophe JAILLET Date: Sat, 20 May 2023 10:13:22 +0200 Subject: wifi: ray_cs: Fix an error handling path in ray_probe() Should ray_config() fail, some resources need to be released as already done in the remove function. While at it, remove a useless and erroneous comment. The probe is ray_probe(), not ray_attach(). Fixes: 15b99ac17295 ("[PATCH] pcmcia: add return value to _config() functions") Signed-off-by: Christophe JAILLET Reviewed-by: Simon Horman Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/8c544d18084f8b37dd108e844f7e79e85ff708ff.1684570373.git.christophe.jaillet@wanadoo.fr --- drivers/net/wireless/legacy/ray_cs.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'drivers/net/wireless/legacy/ray_cs.c') diff --git a/drivers/net/wireless/legacy/ray_cs.c b/drivers/net/wireless/legacy/ray_cs.c index 1f57a0055bbd..38782d4c4694 100644 --- a/drivers/net/wireless/legacy/ray_cs.c +++ b/drivers/net/wireless/legacy/ray_cs.c @@ -270,13 +270,14 @@ static int ray_probe(struct pcmcia_device *p_dev) { ray_dev_t *local; struct net_device *dev; + int ret; dev_dbg(&p_dev->dev, "ray_attach()\n"); /* Allocate space for private device-specific data */ dev = alloc_etherdev(sizeof(ray_dev_t)); if (!dev) - goto fail_alloc_dev; + return -ENOMEM; local = netdev_priv(dev); local->finder = p_dev; @@ -313,11 +314,16 @@ static int ray_probe(struct pcmcia_device *p_dev) timer_setup(&local->timer, NULL, 0); this_device = p_dev; - return ray_config(p_dev); + ret = ray_config(p_dev); + if (ret) + goto err_free_dev; + + return 0; -fail_alloc_dev: - return -ENOMEM; -} /* ray_attach */ +err_free_dev: + free_netdev(dev); + return ret; +} static void ray_detach(struct pcmcia_device *link) { -- cgit v1.2.3 From daef020558bc34e8031263aa7cf9e803d709f93a Mon Sep 17 00:00:00 2001 From: Dongliang Mu Date: Thu, 16 Mar 2023 21:32:35 +0800 Subject: wifi: ray_cs: remove one redundant del_timer In ray_detach, it and its child function ray_release both call del_timer(_sync) on the same timer. Fix this by removing the del_timer_sync in the ray_detach, and revising the del_timer to del_timer_sync. Signed-off-by: Dongliang Mu Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/20230316133236.556198-2-dzm91@hust.edu.cn --- drivers/net/wireless/legacy/ray_cs.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'drivers/net/wireless/legacy/ray_cs.c') diff --git a/drivers/net/wireless/legacy/ray_cs.c b/drivers/net/wireless/legacy/ray_cs.c index 38782d4c4694..93eaf3dba6a9 100644 --- a/drivers/net/wireless/legacy/ray_cs.c +++ b/drivers/net/wireless/legacy/ray_cs.c @@ -328,7 +328,6 @@ err_free_dev: static void ray_detach(struct pcmcia_device *link) { struct net_device *dev; - ray_dev_t *local; dev_dbg(&link->dev, "ray_detach\n"); @@ -337,9 +336,6 @@ static void ray_detach(struct pcmcia_device *link) ray_release(link); - local = netdev_priv(dev); - del_timer_sync(&local->timer); - if (link->priv) { unregister_netdev(dev); free_netdev(dev); @@ -740,7 +736,7 @@ static void ray_release(struct pcmcia_device *link) dev_dbg(&link->dev, "ray_release\n"); - del_timer(&local->timer); + del_timer_sync(&local->timer); iounmap(local->sram); iounmap(local->rmem); -- cgit v1.2.3 From 072210c725c4938682e58236eeeb19a2ddd0b817 Mon Sep 17 00:00:00 2001 From: Dongliang Mu Date: Thu, 16 Mar 2023 21:32:36 +0800 Subject: wifi: ray_cs: add sanity check on local->sram/rmem/amem The ray_config uses ray_release as its unified error handling function. However, it does not know if local->sram/rmem/amem succeeds or not. Fix this by adding sanity check on local->sram/rmem/amem in the ray_relase. Signed-off-by: Dongliang Mu Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/20230316133236.556198-3-dzm91@hust.edu.cn --- drivers/net/wireless/legacy/ray_cs.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'drivers/net/wireless/legacy/ray_cs.c') diff --git a/drivers/net/wireless/legacy/ray_cs.c b/drivers/net/wireless/legacy/ray_cs.c index 93eaf3dba6a9..4b53a9c70e7e 100644 --- a/drivers/net/wireless/legacy/ray_cs.c +++ b/drivers/net/wireless/legacy/ray_cs.c @@ -738,9 +738,12 @@ static void ray_release(struct pcmcia_device *link) del_timer_sync(&local->timer); - iounmap(local->sram); - iounmap(local->rmem); - iounmap(local->amem); + if (local->sram) + iounmap(local->sram); + if (local->rmem) + iounmap(local->rmem); + if (local->amem) + iounmap(local->amem); pcmcia_disable_device(link); dev_dbg(&link->dev, "ray_release ending\n"); -- cgit v1.2.3 From 707a13c7e488785170a5e7f2467f2823824651e2 Mon Sep 17 00:00:00 2001 From: Kalle Valo Date: Tue, 13 Jun 2023 17:09:18 +0300 Subject: wifi: ray_cs: fix stringop-truncation GCC warning GCC 12.2 with W=1 warns: drivers/net/wireless/legacy/ray_cs.c:630:17: warning: 'strncpy' specified bound 32 equals destination size [-Wstringop-truncation] The driver uses SSID as a string which is just wrong, it should be treated as a byte array instead. But as the driver is ancient and most likely there are no users so convert it to use strscpy(). This makes sure that the string is NUL-terminated and also the warning is fixed. Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/20230613140918.389690-5-kvalo@kernel.org --- drivers/net/wireless/legacy/ray_cs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/net/wireless/legacy/ray_cs.c') diff --git a/drivers/net/wireless/legacy/ray_cs.c b/drivers/net/wireless/legacy/ray_cs.c index 4b53a9c70e7e..8ace797ce951 100644 --- a/drivers/net/wireless/legacy/ray_cs.c +++ b/drivers/net/wireless/legacy/ray_cs.c @@ -627,7 +627,7 @@ static void init_startup_params(ray_dev_t *local) local->sparm.b4.a_acting_as_ap_status = TYPE_STA; if (essid != NULL) - strncpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE); + strscpy(local->sparm.b4.a_current_ess_id, essid, ESSID_SIZE); } /* init_startup_params */ /*===========================================================================*/ -- cgit v1.2.3