All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Nihar Panda" <niharp@linux.ibm.com>
Cc: linux-scsi@vger.kernel.org,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>
Subject: Re: [PATCH v2 3/3] zfcp: trace return values of sysfs unit add store
Date: Tue, 28 Jul 2026 05:24:15 +0000	[thread overview]
Message-ID: <20260728052416.111671F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260728044857.2532646-4-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 of port->units on the device_register error path in zfcp_unit_add, leading to integer underflow and port state corruption.
--

--- Patch [3]: [PATCH v2 3/3] zfcp: trace return values of sysfs unit add store ---
commit 5a4c6fdfefd98873215621f0e0b76392831e1659
Author: Chinmaya Kajagar <chinmayk@linux.ibm.com>

zfcp: trace return values of sysfs unit add store

This commit adds a new debug trace to log failures when adding LUNs via the
sysfs unit_add attribute. It records the wwpn, fcp_lun, return value, and
associated hba whenever zfcp_unit_add() or the initial parsing fails.

> diff --git a/drivers/s390/scsi/zfcp_sysfs.c b/drivers/s390/scsi/zfcp_sysfs.c
> --- a/drivers/s390/scsi/zfcp_sysfs.c
> +++ b/drivers/s390/scsi/zfcp_sysfs.c
[ ... ]
> @@ -442,17 +442,24 @@ static ssize_t zfcp_sysfs_unit_add_store(struct device *dev,
[ ... ]
>  	flush_work(&port->rport_work);
>  
> -	retval = zfcp_unit_add(port, fcp_lun);
> -	if (retval)
> +	retval = zfcp_unit_add(port, fcp_lun);

[Severity: High]
This is a pre-existing issue, but since this patch handles and traces
errors returned from zfcp_unit_add(), does this error path contain an
unbalanced decrement?

Looking at zfcp_unit_add() in drivers/s390/scsi/zfcp_unit.c, if
device_register() fails:

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);
    ...
}

The put_device() call triggers the device release callback,
zfcp_unit_release(), which unconditionally decrements port->units:

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

Since device_register() fails before atomic_inc(&port->units) is called,
wouldn't the atomic_dec() in the release callback underflow the
port->units counter, corrupting the port state machine?

> +	if (retval) {
> +		zfcp_dbf_hba_uas("syuast2", 3, adapter, port->wwpn,
> +				 fcp_lun, retval);
>  		return retval;
> +	}
>  
>  	return count;
>  }

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

      reply	other threads:[~2026-07-28  5:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28  4:48 [PATCH v2 0/3] Request to queue zfcp enhancements for upstream merge window Nihar Panda
2026-07-28  4:48 ` [PATCH v2 1/3] zfcp: Enhance fsf status read buffer tracing Nihar Panda
2026-07-28  5:26   ` sashiko-bot
2026-07-28  4:48 ` [PATCH v2 2/3] zfcp: Trace plogi and prli within open port response as payload Nihar Panda
2026-07-28  5:20   ` sashiko-bot
2026-07-28  4:48 ` [PATCH v2 3/3] zfcp: trace return values of sysfs unit add store Nihar Panda
2026-07-28  5:24   ` 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=20260728052416.111671F00A3D@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.