memory: omap-gpmc: simplify locking with guard()
Simplify error handling (less gotos) over locks with guard(). Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/20240823-b4-cleanup-h-guard-v1-3-01668915bd55@linaro.org Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
This commit is contained in:
parent
f1619986d7
commit
c93ad423ed
@ -9,6 +9,7 @@
|
|||||||
* Copyright (C) 2009 Texas Instruments
|
* Copyright (C) 2009 Texas Instruments
|
||||||
* Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
|
* Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
|
||||||
*/
|
*/
|
||||||
|
#include <linux/cleanup.h>
|
||||||
#include <linux/cpu_pm.h>
|
#include <linux/cpu_pm.h>
|
||||||
#include <linux/irq.h>
|
#include <linux/irq.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
@ -989,18 +990,18 @@ int gpmc_cs_request(int cs, unsigned long size, unsigned long *base)
|
|||||||
if (size > (1 << GPMC_SECTION_SHIFT))
|
if (size > (1 << GPMC_SECTION_SHIFT))
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
spin_lock(&gpmc_mem_lock);
|
guard(spinlock)(&gpmc_mem_lock);
|
||||||
if (gpmc_cs_reserved(cs)) {
|
|
||||||
r = -EBUSY;
|
if (gpmc_cs_reserved(cs))
|
||||||
goto out;
|
return -EBUSY;
|
||||||
}
|
|
||||||
if (gpmc_cs_mem_enabled(cs))
|
if (gpmc_cs_mem_enabled(cs))
|
||||||
r = adjust_resource(res, res->start & ~(size - 1), size);
|
r = adjust_resource(res, res->start & ~(size - 1), size);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
r = allocate_resource(&gpmc_mem_root, res, size, 0, ~0,
|
r = allocate_resource(&gpmc_mem_root, res, size, 0, ~0,
|
||||||
size, NULL, NULL);
|
size, NULL, NULL);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto out;
|
return r;
|
||||||
|
|
||||||
/* Disable CS while changing base address and size mask */
|
/* Disable CS while changing base address and size mask */
|
||||||
gpmc_cs_disable_mem(cs);
|
gpmc_cs_disable_mem(cs);
|
||||||
@ -1008,16 +1009,15 @@ int gpmc_cs_request(int cs, unsigned long size, unsigned long *base)
|
|||||||
r = gpmc_cs_set_memconf(cs, res->start, resource_size(res));
|
r = gpmc_cs_set_memconf(cs, res->start, resource_size(res));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
release_resource(res);
|
release_resource(res);
|
||||||
goto out;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enable CS */
|
/* Enable CS */
|
||||||
gpmc_cs_enable_mem(cs);
|
gpmc_cs_enable_mem(cs);
|
||||||
*base = res->start;
|
*base = res->start;
|
||||||
gpmc_cs_set_reserved(cs, 1);
|
gpmc_cs_set_reserved(cs, 1);
|
||||||
out:
|
|
||||||
spin_unlock(&gpmc_mem_lock);
|
return 0;
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(gpmc_cs_request);
|
EXPORT_SYMBOL(gpmc_cs_request);
|
||||||
|
|
||||||
@ -1026,10 +1026,9 @@ void gpmc_cs_free(int cs)
|
|||||||
struct gpmc_cs_data *gpmc;
|
struct gpmc_cs_data *gpmc;
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
|
|
||||||
spin_lock(&gpmc_mem_lock);
|
guard(spinlock)(&gpmc_mem_lock);
|
||||||
if (cs >= gpmc_cs_num || cs < 0 || !gpmc_cs_reserved(cs)) {
|
if (cs >= gpmc_cs_num || cs < 0 || !gpmc_cs_reserved(cs)) {
|
||||||
WARN(1, "Trying to free non-reserved GPMC CS%d\n", cs);
|
WARN(1, "Trying to free non-reserved GPMC CS%d\n", cs);
|
||||||
spin_unlock(&gpmc_mem_lock);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gpmc = &gpmc_cs[cs];
|
gpmc = &gpmc_cs[cs];
|
||||||
@ -1039,7 +1038,6 @@ void gpmc_cs_free(int cs)
|
|||||||
if (res->flags)
|
if (res->flags)
|
||||||
release_resource(res);
|
release_resource(res);
|
||||||
gpmc_cs_set_reserved(cs, 0);
|
gpmc_cs_set_reserved(cs, 0);
|
||||||
spin_unlock(&gpmc_mem_lock);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(gpmc_cs_free);
|
EXPORT_SYMBOL(gpmc_cs_free);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user