* [PATCH] [v2] scsi: zfcp: Fix a double put in zfcp_port_enqueue
@ 2023-09-22 7:46 Dinghao Liu
2023-09-22 21:37 ` Bart Van Assche
0 siblings, 1 reply; 2+ messages in thread
From: Dinghao Liu @ 2023-09-22 7:46 UTC (permalink / raw)
To: dinghao.liu
Cc: linux-scsi, Steffen Maier, Benjamin Block, Heiko Carstens,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger,
Sven Schnelle, James Bottomley, Swen Schillig, Christof Schmitt,
linux-s390, linux-kernel
When device_register() fails, zfcp_port_release() will be called
after put_device(). As a result, zfcp_ccw_adapter_put() will be
called twice: one in zfcp_port_release() and one in the error path
after device_register(). So the reference on the adapter object is
doubly put, which may lead to a premature free. Fix this by adjusting
the error tag after device_register().
Fixes: f3450c7b9172 ("[SCSI] zfcp: Replace local reference counting with common kref")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
---
Changelog:
v2: -Improve the patch description.
-Add a new label 'err_register' to unify code style.
---
drivers/s390/scsi/zfcp_aux.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index df782646e856..ad0ef9546501 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -552,7 +552,7 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn,
if (device_register(&port->dev)) {
put_device(&port->dev);
- goto err_out;
+ goto err_register;
}
write_lock_irq(&adapter->port_list_lock);
@@ -565,5 +565,6 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn,
err_out:
zfcp_ccw_adapter_put(adapter);
+err_register:
return ERR_PTR(retval);
}
--
2.17.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] [v2] scsi: zfcp: Fix a double put in zfcp_port_enqueue
2023-09-22 7:46 [PATCH] [v2] scsi: zfcp: Fix a double put in zfcp_port_enqueue Dinghao Liu
@ 2023-09-22 21:37 ` Bart Van Assche
0 siblings, 0 replies; 2+ messages in thread
From: Bart Van Assche @ 2023-09-22 21:37 UTC (permalink / raw)
To: Dinghao Liu
Cc: linux-scsi, Steffen Maier, Benjamin Block, Heiko Carstens,
Vasily Gorbik, Alexander Gordeev, Christian Borntraeger,
Sven Schnelle, James Bottomley, Swen Schillig, Christof Schmitt,
linux-s390, linux-kernel
On 9/22/23 00:46, Dinghao Liu wrote:
> diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
> index df782646e856..ad0ef9546501 100644
> --- a/drivers/s390/scsi/zfcp_aux.c
> +++ b/drivers/s390/scsi/zfcp_aux.c
> @@ -552,7 +552,7 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn,
>
> if (device_register(&port->dev)) {
> put_device(&port->dev);
> - goto err_out;
> + goto err_register;
> }
>
> write_lock_irq(&adapter->port_list_lock);
> @@ -565,5 +565,6 @@ struct zfcp_port *zfcp_port_enqueue(struct zfcp_adapter *adapter, u64 wwpn,
>
> err_out:
> zfcp_ccw_adapter_put(adapter);
> +err_register:
> return ERR_PTR(retval);
> }
goto labels should be named after the code below the goto label instead
of reflecting where the goto statement comes from.
Thanks,
Bart.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-09-22 21:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-22 7:46 [PATCH] [v2] scsi: zfcp: Fix a double put in zfcp_port_enqueue Dinghao Liu
2023-09-22 21:37 ` Bart Van Assche
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®