From 87fbb7003dbc831eb500401a683b6f2647f8b1a7 Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Mon, 19 Nov 2018 20:06:05 +0200 Subject: [PATCH] dm: mei: fix double fw_reset on uos reboot Edge triggered mevent on sysfs file is triggered immediately after mevent_add(), hence this has to be ignored. The issue that is resolved that the 'first' flag was global and wasn't reset on each mevent_add(). Tracked-On: #1846 Signed-off-by: Tomas Winkler Acked-by: Acked-by: Yu Wang --- devicemodel/hw/pci/virtio/virtio_mei.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/devicemodel/hw/pci/virtio/virtio_mei.c b/devicemodel/hw/pci/virtio/virtio_mei.c index d51841dcf..d4eb1c968 100644 --- a/devicemodel/hw/pci/virtio/virtio_mei.c +++ b/devicemodel/hw/pci/virtio/virtio_mei.c @@ -318,6 +318,7 @@ struct virtio_mei { pthread_mutex_t mutex; struct mevent *reset_mevp; + bool dev_state_first; struct mei_virtio_cfg *config; @@ -1979,7 +1980,6 @@ vmei_stop(struct virtio_mei *vmei) static void vmei_reset_callback(int fd, enum ev_type type, void *param) { - static bool first_time = true; struct virtio_mei *vmei = param; char buf[MEI_DEV_STATE_LEN] = {0}; int sz; @@ -1989,8 +1989,12 @@ vmei_reset_callback(int fd, enum ev_type type, void *param) lseek(fd, 0, SEEK_SET); sz = read(fd, buf, 12); - if (first_time) { - first_time = false; + /* + * edge mevent is hit immediately after add + * as the file is not empty, this has to be ignored + */ + if (vmei->dev_state_first) { + vmei->dev_state_first = false; return; } @@ -2017,6 +2021,7 @@ static int vmei_add_reset_event(struct virtio_mei *vmei) if (dev_state_fd < 0) return -errno; + vmei->dev_state_first = true; vmei->reset_mevp = mevent_add(dev_state_fd, EVF_READ_ET, vmei_reset_callback, vmei); if (!vmei->reset_mevp) {