stdio: Add force parameter to stdio_deregister
In some cases we really want to move forward with a deregister, add a force parameter to allow this, and replace the dev with a nulldev in this case. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
3f78a28037
commit
32d019265d
@ -34,6 +34,9 @@ char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
|
|||||||
#define CONFIG_SYS_DEVICE_NULLDEV 1
|
#define CONFIG_SYS_DEVICE_NULLDEV 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_SYS_STDIO_DEREGISTER
|
||||||
|
#define CONFIG_SYS_DEVICE_NULLDEV 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_SYS_DEVICE_NULLDEV
|
#ifdef CONFIG_SYS_DEVICE_NULLDEV
|
||||||
void nulldev_putc(struct stdio_dev *dev, const char c)
|
void nulldev_putc(struct stdio_dev *dev, const char c)
|
||||||
@ -172,7 +175,7 @@ int stdio_register(struct stdio_dev *dev)
|
|||||||
* returns 0 if success, -1 if device is assigned and 1 if devname not found
|
* returns 0 if success, -1 if device is assigned and 1 if devname not found
|
||||||
*/
|
*/
|
||||||
#ifdef CONFIG_SYS_STDIO_DEREGISTER
|
#ifdef CONFIG_SYS_STDIO_DEREGISTER
|
||||||
int stdio_deregister_dev(struct stdio_dev *dev)
|
int stdio_deregister_dev(struct stdio_dev *dev, int force)
|
||||||
{
|
{
|
||||||
int l;
|
int l;
|
||||||
struct list_head *pos;
|
struct list_head *pos;
|
||||||
@ -181,6 +184,10 @@ int stdio_deregister_dev(struct stdio_dev *dev)
|
|||||||
/* get stdio devices (ListRemoveItem changes the dev list) */
|
/* get stdio devices (ListRemoveItem changes the dev list) */
|
||||||
for (l=0 ; l< MAX_FILES; l++) {
|
for (l=0 ; l< MAX_FILES; l++) {
|
||||||
if (stdio_devices[l] == dev) {
|
if (stdio_devices[l] == dev) {
|
||||||
|
if (force) {
|
||||||
|
strcpy(temp_names[l], "nulldev");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
/* Device is assigned -> report error */
|
/* Device is assigned -> report error */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -202,7 +209,7 @@ int stdio_deregister_dev(struct stdio_dev *dev)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int stdio_deregister(const char *devname)
|
int stdio_deregister(const char *devname, int force)
|
||||||
{
|
{
|
||||||
struct stdio_dev *dev;
|
struct stdio_dev *dev;
|
||||||
|
|
||||||
@ -211,7 +218,7 @@ int stdio_deregister(const char *devname)
|
|||||||
if (!dev) /* device not found */
|
if (!dev) /* device not found */
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
return stdio_deregister_dev(dev);
|
return stdio_deregister_dev(dev, force);
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_SYS_STDIO_DEREGISTER */
|
#endif /* CONFIG_SYS_STDIO_DEREGISTER */
|
||||||
|
|
||||||
|
@ -550,7 +550,7 @@ int drv_usb_kbd_init(void)
|
|||||||
int usb_kbd_deregister(void)
|
int usb_kbd_deregister(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_SYS_STDIO_DEREGISTER
|
#ifdef CONFIG_SYS_STDIO_DEREGISTER
|
||||||
int ret = stdio_deregister(DEVNAME);
|
int ret = stdio_deregister(DEVNAME, 0);
|
||||||
if (ret && ret != -ENODEV)
|
if (ret && ret != -ENODEV)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ static int serial_pre_remove(struct udevice *dev)
|
|||||||
#ifdef CONFIG_SYS_STDIO_DEREGISTER
|
#ifdef CONFIG_SYS_STDIO_DEREGISTER
|
||||||
struct serial_dev_priv *upriv = dev->uclass_priv;
|
struct serial_dev_priv *upriv = dev->uclass_priv;
|
||||||
|
|
||||||
if (stdio_deregister_dev(upriv->sdev))
|
if (stdio_deregister_dev(upriv->sdev), 0)
|
||||||
return -EPERM;
|
return -EPERM;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -103,8 +103,8 @@ int stdio_init(void);
|
|||||||
|
|
||||||
void stdio_print_current_devices(void);
|
void stdio_print_current_devices(void);
|
||||||
#ifdef CONFIG_SYS_STDIO_DEREGISTER
|
#ifdef CONFIG_SYS_STDIO_DEREGISTER
|
||||||
int stdio_deregister(const char *devname);
|
int stdio_deregister(const char *devname, int force);
|
||||||
int stdio_deregister_dev(struct stdio_dev *dev);
|
int stdio_deregister_dev(struct stdio_dev *dev, int force);
|
||||||
#endif
|
#endif
|
||||||
struct list_head* stdio_get_list(void);
|
struct list_head* stdio_get_list(void);
|
||||||
struct stdio_dev* stdio_get_by_name(const char* name);
|
struct stdio_dev* stdio_get_by_name(const char* name);
|
||||||
|
Loading…
Reference in New Issue
Block a user