* [PATCH] net/virtio: check return value when calling pthread_mutex_init
@ 2024-12-20 1:53 Sunyang Wu
2024-12-20 5:24 ` Stephen Hemminger
0 siblings, 1 reply; 2+ messages in thread
From: Sunyang Wu @ 2024-12-20 1:53 UTC (permalink / raw)
To: dev; +Cc: maxime.coquelin, chenbox
Add validation for the return value of the pthread_mutex_init.
Signed-off-by: Sunyang Wu <sunyang.wu@jaguarmicro.com>
---
drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 2997d2bd26..00272cf802 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -735,8 +735,13 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
enum virtio_user_backend_type backend_type)
{
uint64_t backend_features;
+ int ret;
- pthread_mutex_init(&dev->mutex, NULL);
+ ret = pthread_mutex_init(&dev->mutex, NULL);
+ if (ret) {
+ PMD_INIT_LOG(ERR, "(%s) init dev mutex failed", dev->path);
+ return ret;
+ }
strlcpy(dev->path, path, PATH_MAX);
dev->started = 0;
--
2.19.0.rc0.windows.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] net/virtio: check return value when calling pthread_mutex_init
2024-12-20 1:53 [PATCH] net/virtio: check return value when calling pthread_mutex_init Sunyang Wu
@ 2024-12-20 5:24 ` Stephen Hemminger
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2024-12-20 5:24 UTC (permalink / raw)
To: Sunyang Wu; +Cc: dev, maxime.coquelin, chenbox
On Fri, 20 Dec 2024 09:53:26 +0800
Sunyang Wu <sunyang.wu@jaguarmicro.com> wrote:
> Add validation for the return value of the pthread_mutex_init.
>
> Signed-off-by: Sunyang Wu <sunyang.wu@jaguarmicro.com>
> ---
> drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> index 2997d2bd26..00272cf802 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> @@ -735,8 +735,13 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
> enum virtio_user_backend_type backend_type)
> {
> uint64_t backend_features;
> + int ret;
>
> - pthread_mutex_init(&dev->mutex, NULL);
> + ret = pthread_mutex_init(&dev->mutex, NULL);
> + if (ret) {
> + PMD_INIT_LOG(ERR, "(%s) init dev mutex failed", dev->path);
> + return ret;
> + }
> strlcpy(dev->path, path, PATH_MAX);
>
> dev->started = 0;
This is wasted and dead code.
The man page for pthread_mutex_init explicitly says:
RETURN VALUE
pthread_mutex_init always returns 0.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-12-20 5:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-20 1:53 [PATCH] net/virtio: check return value when calling pthread_mutex_init Sunyang Wu
2024-12-20 5:24 ` Stephen Hemminger
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).