netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 0/3] s390/net: Cleanup some code checker findings
@ 2022-05-10  7:05 Alexandra Winter
  2022-05-10  7:05 ` [PATCH net 1/3] s390/ctcm: fix variable dereferenced before check Alexandra Winter
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Alexandra Winter @ 2022-05-10  7:05 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski
  Cc: netdev, linux-s390, Heiko Carstens, Alexandra Winter

clean up smatch findings in legacy code. I was not able to provoke
any real failures on my systems, but other hardware reactions,
timing conditions or compiler output, may cause failures.

There are still 2 smatch warnings left in s390/net:

drivers/s390/net/ctcm_main.c:1326 add_channel() warn: missing error code 'rc'
This one is a false positive.

drivers/s390/net/netiucv.c:1355 netiucv_check_user() warn: argument 3 to %02x specifier has type 'char'
Postponing this one, need to better understand string handling in iucv.

There are several sparse warnings left in ctcm, like:
drivers/s390/net/ctcm_fsms.c:573:9: warning: context imbalance in 'ctcm_chx_setmode' - different lock contexts for basic block
Those are mentioned in the source, no plan to rework.

Alexandra Winter (3):
  s390/ctcm: fix variable dereferenced before check
  s390/ctcm: fix potential memory leak
  s390/lcs: fix variable dereferenced before check

 drivers/s390/net/ctcm_mpc.c   | 6 +-----
 drivers/s390/net/ctcm_sysfs.c | 5 +++--
 drivers/s390/net/lcs.c        | 7 ++++---
 3 files changed, 8 insertions(+), 10 deletions(-)

-- 
2.32.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH net 1/3] s390/ctcm: fix variable dereferenced before check
  2022-05-10  7:05 [PATCH net 0/3] s390/net: Cleanup some code checker findings Alexandra Winter
@ 2022-05-10  7:05 ` Alexandra Winter
  2022-05-10  7:05 ` [PATCH net 2/3] s390/ctcm: fix potential memory leak Alexandra Winter
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Alexandra Winter @ 2022-05-10  7:05 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski
  Cc: netdev, linux-s390, Heiko Carstens, Alexandra Winter, Colin Ian King

Found by cppcheck and smatch.
smatch complains about
drivers/s390/net/ctcm_sysfs.c:43 ctcm_buffer_write() warn: variable dereferenced before check 'priv' (see line 42)

Fixes: 3c09e2647b5e ("ctcm: rename READ/WRITE defines to avoid redefinitions")
Reported-by: Colin Ian King <colin.i.king@gmail.com>
Signed-off-by: Alexandra Winter <wintera@linux.ibm.com>
---
 drivers/s390/net/ctcm_sysfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/s390/net/ctcm_sysfs.c b/drivers/s390/net/ctcm_sysfs.c
index ded1930a00b2..e3813a7aa5e6 100644
--- a/drivers/s390/net/ctcm_sysfs.c
+++ b/drivers/s390/net/ctcm_sysfs.c
@@ -39,11 +39,12 @@ static ssize_t ctcm_buffer_write(struct device *dev,
 	struct ctcm_priv *priv = dev_get_drvdata(dev);
 	int rc;
 
-	ndev = priv->channel[CTCM_READ]->netdev;
-	if (!(priv && priv->channel[CTCM_READ] && ndev)) {
+	if (!(priv && priv->channel[CTCM_READ] &&
+	      priv->channel[CTCM_READ]->netdev)) {
 		CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, "bfnondev");
 		return -ENODEV;
 	}
+	ndev = priv->channel[CTCM_READ]->netdev;
 
 	rc = kstrtouint(buf, 0, &bs1);
 	if (rc)
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 2/3] s390/ctcm: fix potential memory leak
  2022-05-10  7:05 [PATCH net 0/3] s390/net: Cleanup some code checker findings Alexandra Winter
  2022-05-10  7:05 ` [PATCH net 1/3] s390/ctcm: fix variable dereferenced before check Alexandra Winter
@ 2022-05-10  7:05 ` Alexandra Winter
  2022-05-10  7:05 ` [PATCH net 3/3] s390/lcs: fix variable dereferenced before check Alexandra Winter
  2022-05-11 11:40 ` [PATCH net 0/3] s390/net: Cleanup some code checker findings patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Alexandra Winter @ 2022-05-10  7:05 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski
  Cc: netdev, linux-s390, Heiko Carstens, Alexandra Winter

smatch complains about
drivers/s390/net/ctcm_mpc.c:1210 ctcmpc_unpack_skb() warn: possible memory leak of 'mpcginfo'

mpc_action_discontact() did not free mpcginfo. Consolidate the freeing in
ctcmpc_unpack_skb().

Fixes: 293d984f0e36 ("ctcm: infrastructure for replaced ctc driver")
Signed-off-by: Alexandra Winter <wintera@linux.ibm.com>
---
 drivers/s390/net/ctcm_mpc.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/s390/net/ctcm_mpc.c b/drivers/s390/net/ctcm_mpc.c
index 88abfb5e8045..8ac213a55141 100644
--- a/drivers/s390/net/ctcm_mpc.c
+++ b/drivers/s390/net/ctcm_mpc.c
@@ -626,8 +626,6 @@ static void mpc_rcvd_sweep_resp(struct mpcg_info *mpcginfo)
 		ctcm_clear_busy_do(dev);
 	}
 
-	kfree(mpcginfo);
-
 	return;
 
 }
@@ -1192,10 +1190,10 @@ static void ctcmpc_unpack_skb(struct channel *ch, struct sk_buff *pskb)
 						CTCM_FUNTAIL, dev->name);
 			priv->stats.rx_dropped++;
 			/* mpcginfo only used for non-data transfers */
-			kfree(mpcginfo);
 			if (do_debug_data)
 				ctcmpc_dump_skb(pskb, -8);
 		}
+		kfree(mpcginfo);
 	}
 done:
 
@@ -1977,7 +1975,6 @@ static void mpc_action_rcvd_xid0(fsm_instance *fsm, int event, void *arg)
 		}
 		break;
 	}
-	kfree(mpcginfo);
 
 	CTCM_PR_DEBUG("ctcmpc:%s() %s xid2:%i xid7:%i xidt_p2:%i \n",
 		__func__, ch->id, grp->outstanding_xid2,
@@ -2038,7 +2035,6 @@ static void mpc_action_rcvd_xid7(fsm_instance *fsm, int event, void *arg)
 		mpc_validate_xid(mpcginfo);
 		break;
 	}
-	kfree(mpcginfo);
 	return;
 }
 
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH net 3/3] s390/lcs: fix variable dereferenced before check
  2022-05-10  7:05 [PATCH net 0/3] s390/net: Cleanup some code checker findings Alexandra Winter
  2022-05-10  7:05 ` [PATCH net 1/3] s390/ctcm: fix variable dereferenced before check Alexandra Winter
  2022-05-10  7:05 ` [PATCH net 2/3] s390/ctcm: fix potential memory leak Alexandra Winter
@ 2022-05-10  7:05 ` Alexandra Winter
  2022-05-11 11:40 ` [PATCH net 0/3] s390/net: Cleanup some code checker findings patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Alexandra Winter @ 2022-05-10  7:05 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski
  Cc: netdev, linux-s390, Heiko Carstens, Alexandra Winter

smatch complains about
drivers/s390/net/lcs.c:1741 lcs_get_control() warn: variable dereferenced before check 'card->dev' (see line 1739)

Fixes: 27eb5ac8f015 ("[PATCH] s390: lcs driver bug fixes and improvements [1/2]")
Signed-off-by: Alexandra Winter <wintera@linux.ibm.com>
---
 drivers/s390/net/lcs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index bab9b34926c6..84c8981317b4 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -1736,10 +1736,11 @@ lcs_get_control(struct lcs_card *card, struct lcs_cmd *cmd)
 			lcs_schedule_recovery(card);
 			break;
 		case LCS_CMD_STOPLAN:
-			pr_warn("Stoplan for %s initiated by LGW\n",
-				card->dev->name);
-			if (card->dev)
+			if (card->dev) {
+				pr_warn("Stoplan for %s initiated by LGW\n",
+					card->dev->name);
 				netif_carrier_off(card->dev);
+			}
 			break;
 		default:
 			LCS_DBF_TEXT(5, trace, "noLGWcmd");
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net 0/3] s390/net: Cleanup some code checker findings
  2022-05-10  7:05 [PATCH net 0/3] s390/net: Cleanup some code checker findings Alexandra Winter
                   ` (2 preceding siblings ...)
  2022-05-10  7:05 ` [PATCH net 3/3] s390/lcs: fix variable dereferenced before check Alexandra Winter
@ 2022-05-11 11:40 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-05-11 11:40 UTC (permalink / raw)
  To: Alexandra Winter; +Cc: davem, kuba, netdev, linux-s390, hca

Hello:

This series was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Tue, 10 May 2022 09:05:05 +0200 you wrote:
> clean up smatch findings in legacy code. I was not able to provoke
> any real failures on my systems, but other hardware reactions,
> timing conditions or compiler output, may cause failures.
> 
> There are still 2 smatch warnings left in s390/net:
> 
> drivers/s390/net/ctcm_main.c:1326 add_channel() warn: missing error code 'rc'
> This one is a false positive.
> 
> [...]

Here is the summary with links:
  - [net,1/3] s390/ctcm: fix variable dereferenced before check
    https://git.kernel.org/netdev/net/c/2c50c6867c85
  - [net,2/3] s390/ctcm: fix potential memory leak
    https://git.kernel.org/netdev/net/c/0c0b20587b9f
  - [net,3/3] s390/lcs: fix variable dereferenced before check
    https://git.kernel.org/netdev/net/c/671bb35c8e74

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-11 11:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-10  7:05 [PATCH net 0/3] s390/net: Cleanup some code checker findings Alexandra Winter
2022-05-10  7:05 ` [PATCH net 1/3] s390/ctcm: fix variable dereferenced before check Alexandra Winter
2022-05-10  7:05 ` [PATCH net 2/3] s390/ctcm: fix potential memory leak Alexandra Winter
2022-05-10  7:05 ` [PATCH net 3/3] s390/lcs: fix variable dereferenced before check Alexandra Winter
2022-05-11 11:40 ` [PATCH net 0/3] s390/net: Cleanup some code checker findings patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).