Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1192250ybn; Wed, 2 Oct 2019 12:12:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyz5JFTZLpyy/J8TcmyOeCGVeTy/jPfbg1D1bEdVmBtnlxKuqjajfNPoUQd4cDmW2sY2TOD X-Received: by 2002:a50:9e26:: with SMTP id z35mr5501570ede.265.1570043577022; Wed, 02 Oct 2019 12:12:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570043577; cv=none; d=google.com; s=arc-20160816; b=JrC5mLFiI4IYHIqK1m2diWkmkFyNNJue03WQKyg71D4VPJVwfzxHNcTQCYHy7Gg16B MP5tG+qFC3IvebRR8o0guq+M71sEBHTi2ita8CwTpuu5Jny1HIgr+Z0h8dFU/aG/PG5Z ZxyMSNWc6HqvQa8Pe0MRgv+1hdH4YvcUy7U8pZQy829BvNHfCTkIEOFrBVzP1iK0HQ3a WoeKT/EFq1uIMbdV8uqzUO2XoToEVtkPo2VKDUwSzYfN/eI07lRaHKgne8iq14DnQnln dvf5kxXMiXhXacg5QRWg6DL21vchyaa7tnmf8Ate3SbtX8Cga5CMA200FlESV+kljZhI pmYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=4I+yXqIs2jeBGAmJEkaat9W5iWgWjKRWOmM7S+Ou2+U=; b=wztUJW3fwBpnSzy4frpXMfZu6Q9O/6v6IVOXSO+Rjib5HIUxmbWMZZMNaXAN2LDFfy S4XXr26AbcnADzQVvgKTldgTAR2K1ncMvPzizA7UQ617wNCBTdohNPfXWbL6m9A7xoCp gx78AA177S9mJhN0iYN2+TKQ6na4PfurFgMosDu9OjG3WY27JzkMOS4ZZ3EOVDNxwzN1 dZ9/JqLYjcTzG2s/DtX8SqGODsr6c42SKqZz+PLFTeKH1kzL6+9Cw/gmymP8hgPkgZdA j4YHJJSopSL/9dmUytmm8nOkps9/63nYyh4IZ4VkKreCuP07Ac6HsaIINtAN8fe8I9Tz 2pbQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k53si17300edb.303.2019.10.02.12.12.32; Wed, 02 Oct 2019 12:12:57 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729278AbfJBTIO (ORCPT + 99 others); Wed, 2 Oct 2019 15:08:14 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35228 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728996AbfJBTII (ORCPT ); Wed, 2 Oct 2019 15:08:08 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iFjyn-00035G-Cm; Wed, 02 Oct 2019 20:08:05 +0100 Received: from ben by deadeye with local (Exim 4.92.1) (envelope-from ) id 1iFjyn-0003aV-1o; Wed, 02 Oct 2019 20:08:05 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Greg Kroah-Hartman" , "Oliver Neukum" Date: Wed, 02 Oct 2019 20:06:51 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 09/87] USB: rio500: fix memory leak in close after disconnect In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.75-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Oliver Neukum commit e0feb73428b69322dd5caae90b0207de369b5575 upstream. If a disconnected device is closed, rio_close() must free the buffers. Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman Signed-off-by: Ben Hutchings --- drivers/usb/misc/rio500.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) --- a/drivers/usb/misc/rio500.c +++ b/drivers/usb/misc/rio500.c @@ -103,9 +103,22 @@ static int close_rio(struct inode *inode { struct rio_usb_data *rio = &rio_instance; - rio->isopen = 0; + /* against disconnect() */ + mutex_lock(&rio500_mutex); + mutex_lock(&(rio->lock)); - dev_info(&rio->rio_dev->dev, "Rio closed.\n"); + rio->isopen = 0; + if (!rio->present) { + /* cleanup has been delayed */ + kfree(rio->ibuf); + kfree(rio->obuf); + rio->ibuf = NULL; + rio->obuf = NULL; + } else { + dev_info(&rio->rio_dev->dev, "Rio closed.\n"); + } + mutex_unlock(&(rio->lock)); + mutex_unlock(&rio500_mutex); return 0; }