Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp303042pxx; Thu, 29 Oct 2020 03:05:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTucz902/HiUVtWS7S6VYPoKMeIKWC+XS2alhFrqVNFQUnIvmQgwYugjqPEFSSI/70LzoG X-Received: by 2002:a17:906:b03:: with SMTP id u3mr3172234ejg.3.1603965928262; Thu, 29 Oct 2020 03:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603965928; cv=none; d=google.com; s=arc-20160816; b=EMKjvheShyqpC4VEuZef+xP1eRT91ZfXuQm4PWoW7e+xRf+UwWxzmQznXE2m9g2ZJS wRxomq90ptgRpTn921CjplqBsL1I9w+t5UzBN9dxrVHKV8oxVuFYCkepQ8iIrElRbbSH UEa7keP7FClMbZxCeabquVUoYTZGZwCIIfZxAOGlv+GFIDr7JyRuKZU2iKsmu0H2cLpT 0POiGuj1SsE+0cnXi0SDscL0xrAfwspVoJdWb+8DlMpSlqJBDC7WF3CmNSCePfC0yw0A 803GV6DmyKzc2lqTflz1JaQdotZHy8W+561QQdS+Te1lWQE4fi4Cy885s6ECJi/qmsqm 0Cfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=xLmFFqgDF+3yKz+4nNi7eFoq8G/JtueALO6x9sa6R5Y=; b=JUOyAsCOBGPIuI4oA3kd6gqYESZ8GSIMALUv2GTbQ5CnFk+pC1lUhzD4krT8iMc7wQ tLCWGa/P3IEAwMj/fCmoOErxgobH/s2QPm6ElEjlp5khpi6hBXqnTCIFCnKxaUprgUqG GFmb9SDVJJ/ApOPhdMSMyrlAJ3IB0y5UEn9zNrQ1rwJZU7yk7Z1NVbJ3iRsp29aks2KI hNXs8gxMkmzBb/87EWwGpASusqUyrt4WNekLy4BjSUn2DwCowxG8o0VKevBVMBdc6PJL lbSHyxXiU9JghUrk7OFR/H7ud4OiDzS8hnwEM/o+nfj9S7wncXM6MERnaCFVNFR3EmI9 HN/Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id ds19si1275563ejc.306.2020.10.29.03.05.05; Thu, 29 Oct 2020 03:05:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726526AbgJ2Jz0 (ORCPT + 99 others); Thu, 29 Oct 2020 05:55:26 -0400 Received: from mga04.intel.com ([192.55.52.120]:30816 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726419AbgJ2JzY (ORCPT ); Thu, 29 Oct 2020 05:55:24 -0400 IronPort-SDR: 4JaDkanXFJM1tOOSSzVhp/B3hXm9WqFt5EgylwpUAKRD4L1QoJ7bLT4WNQ72F7ZQOP71Gn0snS HxNAtcxAX+AA== X-IronPort-AV: E=McAfee;i="6000,8403,9788"; a="165821752" X-IronPort-AV: E=Sophos;i="5.77,429,1596524400"; d="scan'208";a="165821752" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2020 02:55:23 -0700 IronPort-SDR: HqLVDk1UkwL/Gzlj1IRKrBBc/v8WJMpLJyI7peMzastnSbOCJzjbDGx0F5vi1g2N3buspwmMTT kvQSAI+ozSfg== X-IronPort-AV: E=Sophos;i="5.77,429,1596524400"; d="scan'208";a="536607352" Received: from twinkler-lnx.jer.intel.com ([10.12.91.138]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Oct 2020 02:55:21 -0700 From: Tomas Winkler To: Greg Kroah-Hartman Cc: Alexander Usyskin , linux-kernel@vger.kernel.org, Tomas Winkler Subject: [char-misc-next 2/3] mei: bus: do not start a read for disconnected clients Date: Thu, 29 Oct 2020 11:54:43 +0200 Message-Id: <20201029095444.957924-3-tomas.winkler@intel.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20201029095444.957924-1-tomas.winkler@intel.com> References: <20201029095444.957924-1-tomas.winkler@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexander Usyskin Avoid queuing reads and registering rx callbacks in case the client is not connected, to prevent null dereferencing and memory leaks. Signed-off-by: Alexander Usyskin Signed-off-by: Tomas Winkler --- drivers/misc/mei/bus.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c index 9cdaa7f3af23..1a54bf3ed0c3 100644 --- a/drivers/misc/mei/bus.c +++ b/drivers/misc/mei/bus.c @@ -276,7 +276,8 @@ static void mei_cl_bus_rx_work(struct work_struct *work) cldev->rx_cb(cldev); mutex_lock(&bus->device_lock); - mei_cl_read_start(cldev->cl, mei_cl_mtu(cldev->cl), NULL); + if (mei_cl_is_connected(cldev->cl)) + mei_cl_read_start(cldev->cl, mei_cl_mtu(cldev->cl), NULL); mutex_unlock(&bus->device_lock); } @@ -364,7 +365,10 @@ int mei_cldev_register_rx_cb(struct mei_cl_device *cldev, mei_cldev_cb_t rx_cb) INIT_WORK(&cldev->rx_work, mei_cl_bus_rx_work); mutex_lock(&bus->device_lock); - ret = mei_cl_read_start(cldev->cl, mei_cl_mtu(cldev->cl), NULL); + if (mei_cl_is_connected(cldev->cl)) + ret = mei_cl_read_start(cldev->cl, mei_cl_mtu(cldev->cl), NULL); + else + ret = -ENODEV; mutex_unlock(&bus->device_lock); if (ret && ret != -EBUSY) return ret; -- 2.25.4