From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752876AbbKLAzA (ORCPT ); Wed, 11 Nov 2015 19:55:00 -0500 Received: from p3plsmtps2ded01.prod.phx3.secureserver.net ([208.109.80.58]:37032 "EHLO p3plsmtps2ded01.prod.phx3.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752741AbbKLAyz (ORCPT ); Wed, 11 Nov 2015 19:54:55 -0500 x-originating-ip: 72.167.245.219 From: "K. Y. Srinivasan" To: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com, jasowang@redhat.com Cc: Dexuan Cui , "K. Y. Srinivasan" Subject: [PATCH V2 07/12] Drivers: hv: vmbus: do sanity check of channel state in vmbus_close_internal() Date: Wed, 11 Nov 2015 18:26:19 -0800 Message-Id: <1447295184-9051-7-git-send-email-kys@microsoft.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1447295184-9051-1-git-send-email-kys@microsoft.com> References: <1447295158-9012-1-git-send-email-kys@microsoft.com> <1447295184-9051-1-git-send-email-kys@microsoft.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dexuan Cui This fixes an incorrect assumption of channel state in the function. Signed-off-by: Dexuan Cui Signed-off-by: K. Y. Srinivasan --- drivers/hv/channel.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c index f7f3d5c..00e1be7 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 */ -- 1.7.4.1