Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4204448imc; Mon, 25 Feb 2019 00:18:17 -0800 (PST) X-Google-Smtp-Source: AHgI3IbI/0mHSCAba7dxYnC6jGMoodMHRF13iwqbRm7wQbCDJS04WZ/fAqO4m4VMDLoJIT2aZAIt X-Received: by 2002:a62:484:: with SMTP id 126mr10685830pfe.91.1551082697305; Mon, 25 Feb 2019 00:18:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551082697; cv=none; d=google.com; s=arc-20160816; b=QdmOHV34FGnK0WEMe6ct6Yg7cKPGWs+2sz9ouO6cOogg0/wt4QSSTIY5a10AfnhD6N rS9wBe6T9PmK8hjLmXfBRWd/tcCYWy/AXC7CoL5KTrdrEEYkNRt05xNUgxikqnAByTE1 DOj9PzTNTbU9yoywrPSMjXdu8tJhvVDRSGlMi5wkenIOK70UfMJ++IbS4D7jlQt0gjxc BgnLtzOiWBbMDAhq2aWWLMXYIDgWRIE3DtBUhI+G1juEgksqpfM3Ip8AN6Bny66PKma1 f6mqaWVwpszH71iFoYV7mOiEJr1pz1BoS61pAbsIWbDKJN9J69CBCaw9hN9HfwQmdCQw q/zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Jq0whmndol336Oo2n0+qUPNM9nwGzqZgGyTmvxv3lNc=; b=J+I4fONOxjtbUwlb5Xhn77Poq7+iwqkfC6atkL5Cff84Zlh/FNrn0oa/+UrhdH2kYR 8HF06ad53LKRXRP3ou/fvjH/eEedtPRIi9nVzS3x8n29zJLe3RKazqX7t7gX/jPE9Xe6 k0QeAe+bHVkaAzsNEYPajkauYv1fwtwchXRDUjRSBNAU2jWirxsguzcespAzVNv/o+8m FoICmp0sF9l0E9AyHBPog0hSxyUk5LE5aHMtKhgjK+iuIpClg1lWFQ6SDsEyU8It84VB tMSSP0MaalNVXo4upuRvMm+YQpFFBegqhsK/ZoJKNFejYRSDVUpTAPuQVKCIRyOJU2c2 Je4g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l68si9752423plb.90.2019.02.25.00.18.02; Mon, 25 Feb 2019 00:18:17 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726220AbfBYIRA (ORCPT + 99 others); Mon, 25 Feb 2019 03:17:00 -0500 Received: from mga03.intel.com ([134.134.136.65]:19944 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725942AbfBYIRA (ORCPT ); Mon, 25 Feb 2019 03:17:00 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Feb 2019 00:16:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,410,1544515200"; d="scan'208";a="149703390" Received: from twinkler-lnx.jer.intel.com ([10.12.91.48]) by fmsmga001.fm.intel.com with ESMTP; 25 Feb 2019 00:16:57 -0800 From: Tomas Winkler To: Greg Kroah-Hartman Cc: Alexander Usyskin , linux-kernel@vger.kernel.org, stable@vger.kernel.org, Tomas Winkler Subject: [char-misc-next] mei: bus: move hw module get/put to probe/release Date: Mon, 25 Feb 2019 11:09:28 +0200 Message-Id: <20190225090928.8715-1-tomas.winkler@intel.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Usyskin Fix unbalanced module reference counting during internal reset, which prevents the drivers unloading. Tracking mei_me/txe modules on mei client bus via mei_cldev_enable/disable is error prone due to possible internal reset flow, where clients are disconnected underneath. Moving reference counting to probe and release of mei bus client driver solves this issue in simplest way, as each client provides only a single connection to a client bus driver. Cc: Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler --- drivers/misc/mei/bus.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c index e5456faf00e6..65bec998eb6e 100644 --- a/drivers/misc/mei/bus.c +++ b/drivers/misc/mei/bus.c @@ -540,17 +540,9 @@ int mei_cldev_enable(struct mei_cl_device *cldev) goto out; } - if (!mei_cl_bus_module_get(cldev)) { - dev_err(&cldev->dev, "get hw module failed"); - ret = -ENODEV; - goto out; - } - ret = mei_cl_connect(cl, cldev->me_cl, NULL); - if (ret < 0) { + if (ret < 0) dev_err(&cldev->dev, "cannot connect\n"); - mei_cl_bus_module_put(cldev); - } out: mutex_unlock(&bus->device_lock); @@ -613,7 +605,6 @@ int mei_cldev_disable(struct mei_cl_device *cldev) if (err < 0) dev_err(bus->dev, "Could not disconnect from the ME client\n"); - mei_cl_bus_module_put(cldev); out: /* Flush queues and remove any pending read */ mei_cl_flush_queues(cl, NULL); @@ -724,9 +715,16 @@ static int mei_cl_device_probe(struct device *dev) if (!id) return -ENODEV; + if (!mei_cl_bus_module_get(cldev)) { + dev_err(&cldev->dev, "get hw module failed"); + return -ENODEV; + } + ret = cldrv->probe(cldev, id); - if (ret) + if (ret) { + mei_cl_bus_module_put(cldev); return ret; + } __module_get(THIS_MODULE); return 0; @@ -754,6 +752,7 @@ static int mei_cl_device_remove(struct device *dev) mei_cldev_unregister_callbacks(cldev); + mei_cl_bus_module_put(cldev); module_put(THIS_MODULE); dev->driver = NULL; return ret; -- 2.20.1