mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-30 00:21:06 +00:00
c726fc01cf
There is a number of users that use uclass_first_device to access the first and (assumed) only device in uclass. Some check the return value of uclass_first_device and also that a device was returned which is exactly what uclass_first_device_err does. Some are not checking that a device was returned and can potentially crash if no device exists in the uclass. Finally there is one that returns NULL on error either way. Convert all of these to use uclass_first_device_err instead, the return value will be removed from uclass_first_device in a later patch. Signed-off-by: Michal Suchanek <msuchanek@suse.de> Reviewed-by: Simon Glass <sjg@chromium.org>
58 lines
1 KiB
C
58 lines
1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* (C) Copyright 2016 Google, Inc
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <dm.h>
|
|
#include <errno.h>
|
|
#include <log.h>
|
|
#include <sysreset.h>
|
|
#include <wdt.h>
|
|
#include <asm/io.h>
|
|
#include <asm/arch/wdt.h>
|
|
#include <linux/err.h>
|
|
#include <hang.h>
|
|
|
|
static int ast_sysreset_request(struct udevice *dev, enum sysreset_t type)
|
|
{
|
|
struct udevice *wdt;
|
|
u32 reset_mode;
|
|
int ret = uclass_first_device_err(UCLASS_WDT, &wdt);
|
|
|
|
if (ret)
|
|
return ret;
|
|
|
|
switch (type) {
|
|
case SYSRESET_WARM:
|
|
reset_mode = WDT_CTRL_RESET_CPU;
|
|
break;
|
|
case SYSRESET_COLD:
|
|
reset_mode = WDT_CTRL_RESET_CHIP;
|
|
break;
|
|
default:
|
|
return -EPROTONOSUPPORT;
|
|
}
|
|
|
|
#if !defined(CONFIG_SPL_BUILD)
|
|
ret = wdt_expire_now(wdt, reset_mode);
|
|
if (ret) {
|
|
debug("Sysreset failed: %d", ret);
|
|
return ret;
|
|
}
|
|
#else
|
|
hang();
|
|
#endif
|
|
|
|
return -EINPROGRESS;
|
|
}
|
|
|
|
static struct sysreset_ops ast_sysreset = {
|
|
.request = ast_sysreset_request,
|
|
};
|
|
|
|
U_BOOT_DRIVER(sysreset_ast) = {
|
|
.name = "ast_sysreset",
|
|
.id = UCLASS_SYSRESET,
|
|
.ops = &ast_sysreset,
|
|
};
|