Skip to content

Commit 6703784

Browse files
Bartosz GolaszewskipH5
authored andcommitted
reset: fold ida_alloc() into reset_create_gpio_aux_device()
We don't need to know the IDA value outside of the function that creates the auxiliary reset-gpio device. Simplify error handling by folding it into reset_create_gpio_aux_device(). Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com> Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
1 parent 20adbf3 commit 6703784

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

drivers/reset/core.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,14 @@ static void reset_gpio_aux_device_release(struct device *dev)
824824
}
825825

826826
static int reset_create_gpio_aux_device(struct reset_gpio_lookup *rgpio_dev,
827-
struct device *parent, int id)
827+
struct device *parent)
828828
{
829829
struct auxiliary_device *adev = &rgpio_dev->adev;
830-
int ret;
830+
int ret, id;
831+
832+
id = ida_alloc(&reset_gpio_ida, GFP_KERNEL);
833+
if (id < 0)
834+
return -ENOMEM;
831835

832836
adev->id = id;
833837
adev->name = "gpio";
@@ -837,12 +841,15 @@ static int reset_create_gpio_aux_device(struct reset_gpio_lookup *rgpio_dev,
837841
device_set_node(&adev->dev, rgpio_dev->swnode);
838842

839843
ret = auxiliary_device_init(adev);
840-
if (ret)
844+
if (ret) {
845+
ida_free(&reset_gpio_ida, id);
841846
return ret;
847+
}
842848

843849
ret = __auxiliary_device_add(adev, "reset");
844850
if (ret) {
845851
auxiliary_device_uninit(adev);
852+
ida_free(&reset_gpio_ida, id);
846853
return ret;
847854
}
848855

@@ -891,7 +898,7 @@ static int __reset_add_reset_gpio_device(struct device_node *np,
891898
unsigned int offset, of_flags, lflags;
892899
struct reset_gpio_lookup *rgpio_dev;
893900
struct device *parent;
894-
int id, ret, prop = 0;
901+
int ret, prop = 0;
895902

896903
/*
897904
* Currently only #gpio-cells=2 is supported with the meaning of:
@@ -951,16 +958,10 @@ static int __reset_add_reset_gpio_device(struct device_node *np,
951958
properties[prop++] = PROPERTY_ENTRY_STRING("compatible", "reset-gpio");
952959
properties[prop++] = PROPERTY_ENTRY_GPIO("reset-gpios", parent->fwnode, offset, lflags);
953960

954-
id = ida_alloc(&reset_gpio_ida, GFP_KERNEL);
955-
if (id < 0)
956-
return id;
957-
958961
/* Not freed on success, because it is persisent subsystem data. */
959962
rgpio_dev = kzalloc_obj(*rgpio_dev);
960-
if (!rgpio_dev) {
961-
ret = -ENOMEM;
962-
goto err_ida_free;
963-
}
963+
if (!rgpio_dev)
964+
return -ENOMEM;
964965

965966
rgpio_dev->of_args = *args;
966967
/*
@@ -976,7 +977,7 @@ static int __reset_add_reset_gpio_device(struct device_node *np,
976977
goto err_put_of_node;
977978
}
978979

979-
ret = reset_create_gpio_aux_device(rgpio_dev, parent, id);
980+
ret = reset_create_gpio_aux_device(rgpio_dev, parent);
980981
if (ret)
981982
goto err_del_swnode;
982983

@@ -990,8 +991,6 @@ static int __reset_add_reset_gpio_device(struct device_node *np,
990991
err_put_of_node:
991992
of_node_put(rgpio_dev->of_args.np);
992993
kfree(rgpio_dev);
993-
err_ida_free:
994-
ida_free(&reset_gpio_ida, id);
995994

996995
return ret;
997996
}

0 commit comments

Comments
 (0)