From c43466a98fcb93dcba77f25a8a503415ed5549f2 Mon Sep 17 00:00:00 2001 From: Bjorn Andersson Date: Mon, 25 Jan 2021 18:48:04 -0600 Subject: [PATCH] device: Invoke device->close on exit Allow the control device to implement things such as flushing the command buffer as part of the close operation. This used to be done to ensure that any lingering power/usb off requests really where sent to the device as we closed the control tty. Signed-off-by: Bjorn Andersson --- cdb_assist.c | 4 +++- cdb_assist.h | 2 +- device.c | 3 +++ device.h | 1 + device_parser.c | 1 + 5 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cdb_assist.c b/cdb_assist.c index 4122e6a..92d9cf3 100644 --- a/cdb_assist.c +++ b/cdb_assist.c @@ -293,8 +293,10 @@ void *cdb_assist_open(struct device *dev) return cdb; } -void cdb_assist_close(struct cdb_assist *cdb) +void cdb_assist_close(struct device *dev) { + struct cdb_assist *cdb = dev->cdb; + tcflush(cdb->control_tty, TCIFLUSH); close(cdb->control_tty); diff --git a/cdb_assist.h b/cdb_assist.h index b01374b..babcd65 100644 --- a/cdb_assist.h +++ b/cdb_assist.h @@ -8,7 +8,7 @@ struct cdb_assist; void *cdb_assist_open(struct device *dev); -void cdb_assist_close(struct cdb_assist *cdb); +void cdb_assist_close(struct device *dev); int cdb_assist_power(struct device *dev, bool on); void cdb_assist_usb(struct device *dev, bool on); diff --git a/device.c b/device.c index 642c875..78322d9 100644 --- a/device.c +++ b/device.c @@ -311,4 +311,7 @@ void device_close(struct device *dev) { device_usb(dev, false); device_power(dev, false); + + if (dev->close) + dev->close(dev); } diff --git a/device.h b/device.h index 6dfd0e0..4077d4e 100644 --- a/device.h +++ b/device.h @@ -26,6 +26,7 @@ struct device { void (*boot)(struct device *); void *(*open)(struct device *dev); + void (*close)(struct device *dev); int (*power)(struct device *dev, bool on); void (*usb)(struct device *dev, bool on); void (*print_status)(struct device *dev); diff --git a/device_parser.c b/device_parser.c index 8cc6595..5f208bc 100644 --- a/device_parser.c +++ b/device_parser.c @@ -99,6 +99,7 @@ static void parse_board(struct device_parser *dp) dev->control_dev = strdup(value); dev->open = cdb_assist_open; + dev->close = cdb_assist_close; dev->power = cdb_assist_power; dev->print_status = cdb_assist_print_status; dev->usb = cdb_assist_usb;