[Qemu-devel] [PATCH v2 2/2] qdev: Constify local variable returned by blk_bs

Krzysztof Kozlowski posted 2 patches 8 years, 8 months ago
[Qemu-devel] [PATCH v2 2/2] qdev: Constify local variable returned by blk_bs
Posted by Krzysztof Kozlowski 8 years, 8 months ago
Inside qdev_prop_set_drive() the value returned by blk_bs() is passed
only as pointer to const to bdrv_get_node_name() and pointed values is
not modified in other places so this can be made const for code
safeness.

Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>
---
 hw/core/qdev-properties-system.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index c34be1c1bace..0d40ce682d05 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -405,7 +405,7 @@ void qdev_prop_set_drive(DeviceState *dev, const char *name,
     if (value) {
         ref = blk_name(value);
         if (!*ref) {
-            BlockDriverState *bs = blk_bs(value);
+            const BlockDriverState *bs = blk_bs(value);
             if (bs) {
                 ref = bdrv_get_node_name(bs);
             }
-- 
2.9.3


Re: [Qemu-devel] [PATCH v2 2/2] qdev: Constify local variable returned by blk_bs
Posted by Eduardo Habkost 8 years, 7 months ago
On Fri, Mar 10, 2017 at 10:05:50PM +0200, Krzysztof Kozlowski wrote:
> Inside qdev_prop_set_drive() the value returned by blk_bs() is passed
> only as pointer to const to bdrv_get_node_name() and pointed values is
> not modified in other places so this can be made const for code
> safeness.
> 
> Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

Unless another maintainer wants to take this, I am queueing it
for 2.10 on my machine-next branch.

> ---
>  hw/core/qdev-properties-system.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
> index c34be1c1bace..0d40ce682d05 100644
> --- a/hw/core/qdev-properties-system.c
> +++ b/hw/core/qdev-properties-system.c
> @@ -405,7 +405,7 @@ void qdev_prop_set_drive(DeviceState *dev, const char *name,
>      if (value) {
>          ref = blk_name(value);
>          if (!*ref) {
> -            BlockDriverState *bs = blk_bs(value);
> +            const BlockDriverState *bs = blk_bs(value);
>              if (bs) {
>                  ref = bdrv_get_node_name(bs);
>              }
> -- 
> 2.9.3
> 

-- 
Eduardo