/* SPDX-License-Identifier: GPL-2.0-only */ #include #include #include static void serial_putchar(struct tty *tty, char c) { list_t *list = tty->priv; if (!list) return; list_item_t *item = list->head; while (item) { struct tty *next = item->ptr; next->serial_ops.serial_putchar(next, c); item = item->next; } } static char serial_getchar(struct tty *tty) { /* can't read from a tee, duh */ return 0; } struct tty *tty_tee_create(const char *name) { static struct tty_serial_ops ops = {.serial_putchar = serial_putchar, .serial_getchar = serial_getchar}; list_t *list = kzalloc(sizeof(list_t), ALLOC_KERN); if (!list) return NULL; list_create(list); struct tty *ret = tty_create(name, list); if (!ret) { list_lock(list); list_destroy(list); list_unlock(list); kfree(list); return NULL; } ret->serial_ops = ops; return ret; } void tty_tee_add(struct tty *tee, struct tty *child) { if (!child) return; list_t *list = tee->priv; list_lock(list); list_insert(list, child); list_unlock(list); } void tty_tee_remove(struct tty *tee, struct tty *child) { list_t *list = tee->priv; if (!list) return; list_lock(list); list_item_t *item = list->head; while (item) { if (item->ptr == child) { list_remove(item); list_unlock(list); return; } item = item->next; } list_unlock(list); }