Linux s390 Architecture development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nihar Panda" <niharp@linux.ibm.com>
Cc: linux-scsi@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	linux-s390@vger.kernel.org
Subject: Re: [PATCH 4/4] fixup! zfcp: trace return values of sysfs unit add store
Date: Fri, 24 Jul 2026 06:13:21 +0000	[thread overview]
Message-ID: <20260724061322.6C9DB1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260724053934.2781087-5-niharp@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Unbalanced atomic_dec on error path causes state corruption in `zfcp_unit_add()`, permanently bricking the port.
--

--- Patch [4]: [PATCH 4/4] fixup! zfcp: trace return values of sysfs unit add store ---
commit ccd7f94929b859d2a706671b750a2197236c689b
Author: Nihar Panda <niharp@linux.ibm.com>

fixup! zfcp: trace return values of sysfs unit add store

upstream discussions...

> diff --git a/drivers/s390/scsi/zfcp_sysfs.c b/drivers/s390/scsi/zfcp_sysfs.c
> index 729c9664a48f8..597e04cdcc976 100644
> --- a/drivers/s390/scsi/zfcp_sysfs.c
> +++ b/drivers/s390/scsi/zfcp_sysfs.c
> @@ -443,7 +443,7 @@ static ssize_t zfcp_sysfs_unit_add_store(struct device *dev,
>  {
>  	struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
>  	struct zfcp_adapter *adapter = port->adapter;
> -	u64 fcp_lun;
> +	u64 fcp_lun = 0x0ULL;
>  	int retval = -EINVAL;
>  
>  	if (kstrtoull(buf, 0, (unsigned long long *)&fcp_lun)) {
>  		zfcp_dbf_hba_uas("syuast1", 3, adapter, port->wwpn,
>  				 fcp_lun, retval);
>  		return retval;
>  	}
> 
>  	flush_work(&port->rport_work);
> 
>  	retval = zfcp_unit_add(port, fcp_lun);

[Severity: High]
This is a pre-existing issue, but does zfcp_unit_add() have an unbalanced
atomic_dec() on its error path that can cause state corruption?

If device_register() fails in zfcp_unit_add(), put_device() is called which
invokes zfcp_unit_release():

drivers/s390/scsi/zfcp_unit.c:zfcp_unit_release() {
	...
	atomic_dec(&unit->port->units);
	kfree(unit);
}

However, atomic_inc(&port->units) is only called after a successful
device_register() in zfcp_unit_add():

drivers/s390/scsi/zfcp_unit.c:zfcp_unit_add() {
	...
	if (device_register(&unit->dev)) {
		put_device(&unit->dev);
		retval = -ENOMEM;
		goto out;
	}

	atomic_inc(&port->units);
	...
}

Because the decrement happens even if the increment hasn't, a failure in
device_register() would drop port->units to -1. Since -1 is used as a
sentinel by zfcp_sysfs_port_is_removing() to determine if a port is
permanently removed, would this failure permanently prevent all future
zfcp_unit_add() operations and SCSI scans on this port?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260724053934.2781087-1-niharp@linux.ibm.com?part=4

      reply	other threads:[~2026-07-24  6:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24  5:39 [PATCH 0/4] Request to queue zfcp enhancements for upstream v7.3 merge window Nihar Panda
2026-07-24  5:39 ` [PATCH 1/4] zfcp: Enhance fsf status read buffer tracing Nihar Panda
2026-07-24  6:18   ` sashiko-bot
2026-07-24  5:39 ` [PATCH 2/4] zfcp: Trace plogi and prli within open port response as payload Nihar Panda
2026-07-24  6:11   ` sashiko-bot
2026-07-24  5:39 ` [PATCH 3/4] zfcp: trace return values of sysfs unit add store Nihar Panda
2026-07-24  6:09   ` sashiko-bot
2026-07-24  5:39 ` [PATCH 4/4] fixup! " Nihar Panda
2026-07-24  6:13   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260724061322.6C9DB1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=niharp@linux.ibm.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox