From: Dexuan Cui Date: Tue, 15 Dec 2015 00:01:48 +0000 (-0800) Subject: Drivers: hv: vmbus: do sanity check of channel state in vmbus_close_internal() X-Git-Tag: v4.13~3859^2~36 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=64b7faf903dae2df94d89edf2c688b16751800e4;p=mirror_ubuntu-bionic-kernel.git Drivers: hv: vmbus: do sanity check of channel state in vmbus_close_internal() This fixes an incorrect assumption of channel state in the function. Signed-off-by: Dexuan Cui Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index f7f3d5ccd6bd..00e1be775908 100644 --- a/drivers/hv/channel.c +++ b/drivers/hv/channel.c @@ -512,6 +512,18 @@ static int vmbus_close_internal(struct vmbus_channel *channel) tasklet = hv_context.event_dpc[channel->target_cpu]; tasklet_disable(tasklet); + /* + * In case a device driver's probe() fails (e.g., + * util_probe() -> vmbus_open() returns -ENOMEM) and the device is + * rescinded later (e.g., we dynamically disble an Integrated Service + * in Hyper-V Manager), the driver's remove() invokes vmbus_close(): + * here we should skip most of the below cleanup work. + */ + if (channel->state != CHANNEL_OPENED_STATE) { + ret = -EINVAL; + goto out; + } + channel->state = CHANNEL_OPEN_STATE; channel->sc_creation_callback = NULL; /* Stop callback and cancel the timer asap */