util/async: avoid useless cast
PATCH 1/3 util/async: avoid useless cast
event_notifier_dummy_cb is already compatible with EventNotifierHandler.
--- util/async.c | 1 - 1 file changed, 1 deletion(-)
util/async.c +0 -1
@@ -425,7 +425,6 @@ AioContext *aio_context_new(Error **errp)aio_set_event_notifier (ctx, &ctx->notifier, false, - (EventNotifierHandler *) event_notifier_dummy_cb, event_notifier_poll);#ifdef CONFIG_LINUX_AIO
Signature · 1 line
2.21.0
PATCH 2/3 event_notifier: avoid dandling file descriptor in event_notifier_cleanup
If rfd is equal to wfd the file descriptor is closed but rfd will still have the closed value.
The EventNotifier structure should not be used again after calling event_notifier_cleanup or should be initialized again but make sure to not have dandling file descriptors around.
--- util/event_notifier-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/event_notifier-posix.c +1 -1
@@ -80,8 +80,8 @@ void event_notifier_cleanup(EventNotifier *e) {if (e->rfd != e->wfd) {close (e->rfd); - e->rfd =-1 ; } + e->rfd =-1 ;close (e->wfd); e->wfd =-1 ; }
Signature · 1 line
2.21.0
Re: [PATCH 2/3] event_notifier: avoid dandling file descriptor in event_notifier_cleanup
Le 27/09/2019 à 12:32, Frediano Ziglio a écrit :
Quoted 17 lines
If rfd is equal to wfd the file descriptor is closed but rfd will still have the closed value.
The EventNotifier structure should not be used again after callingevent_notifier_cleanupor should be initialized again but make sure to not have dandling file descriptors around.Signed-off-by Frediano Ziglio <[email protected]>--- util/event_notifier-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)util/event_notifier-posix.c +0
-0
util/event_notifier-posix.c void event_notifier_cleanup(EventNotifier *e) · line 87
Quoted 9 lines
util/event_notifier-posix.c +1
-1@@ -80,8 +80,8 @@ void event_notifier_cleanup(EventNotifier *e) {if (e->rfd != e->wfd) {close (e->rfd); - e->rfd =-1 ; } + e->rfd =-1 ;close (e->wfd); e->wfd =-1 ; }
Le 27/09/2019 à 12:32, Frediano Ziglio a écrit :
Quoted 13 lines
event_notifier_dummy_cbis already compatible with EventNotifierHandler.Signed-off-by Frediano Ziglio <[email protected]>--- util/async.c | 1 - 1 file changed, 1 deletion(-)util/async.c +0
-0
util/async.c AioContext *aio_context_new(Error **errp) · line 430
Quoted 7 lines
util/async.c +0
-1@@ -425,7 +425,6 @@ AioContext *aio_context_new(Error **errp)aio_set_event_notifier (ctx, &ctx->notifier, false, - (EventNotifierHandler *) event_notifier_dummy_cb, event_notifier_poll);#ifdef CONFIG_LINUX_AIO
PATCH 3/3 qemu-timer: reuse MIN macro in qemu_timeout_ns_to_ms
In reply to Frediano Ziglio--- util/qemu-timer.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
util/qemu-timer.c +1 -5
@@ -322,11 +322,7 @@ int qemu_timeout_ns_to_ms(int64_t ns) ms =DIV_ROUND_UP (ns,SCALE_MS );/* To avoid overflow problems, limit this to 2^31, i.e. approx 25 days */ -if (ms > (int64_t )INT32_MAX ) { - ms =INT32_MAX ; - } - -return (int ) ms; +return (int )MIN (ms,INT32_MAX ); }
Signature · 1 line
2.21.0
Re: [PATCH 3/3] qemu-timer: reuse MIN macro in qemu_timeout_ns_to_ms
Le 27/09/2019 à 12:32, Frediano Ziglio a écrit :
Quoted 11 lines
Signed-off-by Frediano Ziglio <[email protected]>--- util/qemu-timer.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)util/qemu-timer.c +0
-0@@ -322,11 +322,7 @@ int qemu_timeout_ns_to_ms(int64_t ns) ms =DIV_ROUND_UP (ns,SCALE_MS );
util/qemu-timer.c int qemu_timeout_ns_to_ms(int64_t ns) · line 327
Quoted 10 lines
util/qemu-timer.c +1
-5/* To avoid overflow problems, limit this to 2^31, i.e. approx 25 days */ -if (ms > (int64_t )INT32_MAX ) { - ms =INT32_MAX ; - } - -return (int ) ms; +return (int )MIN (ms,INT32_MAX ); }
Perhaps it would be cleaner to have always the same return type for MIN() with:
MIN(ms, (int64_t) INT32_MAX)
Anyway:
Thanks,
Laurent
Re: [PATCH 3/3] qemu-timer: reuse MIN macro in qemu_timeout_ns_to_ms
Quoted 28 lines
Le 27/09/2019 à 12:32, Frediano Ziglio a écrit :
Quoted 12 lines
Signed-off-by Frediano Ziglio <[email protected]>--- util/qemu-timer.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)util/qemu-timer.c +0
-0@@ -322,11 +322,7 @@ int qemu_timeout_ns_to_ms(int64_t ns) ms =DIV_ROUND_UP (ns,SCALE_MS );util/qemu-timer.c int qemu_timeout_ns_to_ms(int64_t ns) · line 328
Quoted 10 lines
util/qemu-timer.c +1
-5/* To avoid overflow problems, limit this to 2^31, i.e. approx 25 days */ -if (ms > (int64_t )INT32_MAX ) { - ms =INT32_MAX ; - } - -return (int ) ms; +return (int )MIN (ms,INT32_MAX ); }Perhaps it would be cleaner to have always the same return type for
MIN()with:
Quoted 2 lines
MIN(ms, (int64_t) INT32_MAX)
The (int64_t) cast here is useless, ms is signed, C compilers knows how to convert and compare properly.
The function returns int and it's used in some cases to fill 32bit integer, changing the return type to int64_t is not trivial.
But I suppose that here you mean instead that the 2 sides of the ternary operator used by MIN macro are int64_t and (probably) int32_t. In this case feel free to add the cast with a
return (int) MIN(ms, (int64_t) INT32_MAX);
Quoted 7 lines
Anyway:
Reviewed-by Laurent Vivier <[email protected]>Thanks,
Laurent
Frediano
Re: [PATCH 3/3] qemu-timer: reuse MIN macro in qemu_timeout_ns_to_ms
Le 27/09/2019 à 13:57, Frediano Ziglio a écrit :
Quoted 28 lines
Quoted 28 lines
Le 27/09/2019 à 12:32, Frediano Ziglio a écrit :
Quoted 12 lines
Signed-off-by Frediano Ziglio <[email protected]>--- util/qemu-timer.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)util/qemu-timer.c +0
-0@@ -322,11 +322,7 @@ int qemu_timeout_ns_to_ms(int64_t ns) ms =DIV_ROUND_UP (ns,SCALE_MS );util/qemu-timer.c int qemu_timeout_ns_to_ms(int64_t ns) · line 328
Quoted 10 lines
util/qemu-timer.c +1
-5/* To avoid overflow problems, limit this to 2^31, i.e. approx 25 days */ -if (ms > (int64_t )INT32_MAX ) { - ms =INT32_MAX ; - } - -return (int ) ms; +return (int )MIN (ms,INT32_MAX ); }Perhaps it would be cleaner to have always the same return type for
MIN()with:
Quoted 5 lines
Quoted 2 lines
MIN(ms, (int64_t) INT32_MAX)The (
int64_t) cast here is useless, ms is signed, C compilers knows how to convert and compare properly.
I agree.
Quoted 4 lines
The function returns int and it's used in some cases to fill 32bit integer, changing the return type to
int64_tis not trivial.
But I suppose that here you mean instead that the 2 sides of the ternary operator used by MIN macro areint64_tand (probably)int32_t. In this case
Yes, it's what I mean.
Thanks,
Laurent
Please re-send your series to [email protected] if you want to have it merged.
Thanks,
Laurent
Le 27/09/2019 à 12:32, Frediano Ziglio a écrit :
Quoted 20 lines
event_notifier_dummy_cbis already compatible with EventNotifierHandler.Signed-off-by Frediano Ziglio <[email protected]>--- util/async.c | 1 - 1 file changed, 1 deletion(-)util/async.c +0
-1@@ -425,7 +425,6 @@ AioContext *aio_context_new(Error **errp)aio_set_event_notifier (ctx, &ctx->notifier, false, - (EventNotifierHandler *) event_notifier_dummy_cb, event_notifier_poll);#ifdef CONFIG_LINUX_AIO