Re: [PATCH 2/3] s390/pci: Rework__zpci_event_availability() to remove conditional locking

[email protected] Mon, 03 Aug 2026 10:17:59 +0000
Newsgroups org.kernel.vger.linux-s390
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] The `zdev` reference obtained via `get_zdev_by_fid()` is leaked when handling the `0x0306` PCI event.
--

--- Patch [2]: [PATCH 2/3] s390/pci: Rework__zpci_event_availability() to remove conditional locking ---
commit abeb29e9ac48aa95001741be64e50a68bcadf6fd
Author: Heiko Carstens <[email protected]>

s390/pci: Rework__zpci_event_availability() to remove conditional locking

This commit refactors the __zpci_event_availability() function to avoid
taking the device state lock conditionally. The restructuring handles
different PCI event codes explicitly to resolve static analysis warnings.

> diff --git a/arch/s390/pci/pci_event.c b/arch/s390/pci/pci_event.c
> index 48fa26dcbee14..37acee2c7d257 100644
> --- a/arch/s390/pci/pci_event.c
> +++ b/arch/s390/pci/pci_event.c
> @@ -390,18 +390,21 @@ static void zpci_event_reappear(struct zpci_dev *zdev)
>  static void __zpci_event_availability(struct zpci_ccdf_avail *ccdf)
>  {
>  	struct zpci_dev *zdev = get_zdev_by_fid(ccdf->fid);
> -	bool existing_zdev = !!zdev;
>  	enum zpci_state state;
>  
>  	zpci_dbg(3, "avl fid:%x, fh:%x, pec:%x\n",
>  		 ccdf->fid, ccdf->fh, ccdf->pec);
>  
> -	if (existing_zdev)
> -		mutex_lock(&zdev->state_lock);
> +	if (ccdf->pec == 0x0306) {
> +		/* 0x308 or 0x302 for multiple devices */
> +		zpci_remove_reserved_devices();
> +		zpci_scan_devices();
> +		return;

[Severity: High]
Does this early return leak the zdev reference?

If get_zdev_by_fid() finds an existing device, it increments its reference
count. By returning directly here when the event code is 0x0306, it seems we
skip calling zpci_zdev_put() at the end of the function. Could this prevent
the device from being properly freed during hot-unplug over time?

> +	}
>  
> -	switch (ccdf->pec) {
> -	case 0x0301: /* Reserved|Standby -> Configured */
> -		if (!zdev) {

[ ... ]

-- 
Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=2