Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8041276ybn; Tue, 1 Oct 2019 02:10:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqybt5afQOeoNOkTbAqViqNXroP0u2yT+vnaD+LslpkLbCR/Dqy3nyN/Jj6FE2rEF8/aWErY X-Received: by 2002:a50:a666:: with SMTP id d93mr24207432edc.217.1569921052547; Tue, 01 Oct 2019 02:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569921052; cv=none; d=google.com; s=arc-20160816; b=y0xZv9+Uu1E2NQ2lIwAevvlOvgwY09SjLbbiPOaRGltwzVL8xXNKBUMf4CF2iQBqd/ iU8fXUbNHC7ujDR/bUUu2y9OhTf+YGYcfHOPcTT9hMXX+xKcmtngSmktUdpN8v9r6yVy EX7D6ILtiNrforORogy4YOFILQkaxVFSV/skiJGfNMU/DaqB9pMAmrZBtwNa6sMSgrf+ /qSU6/zaaChZEcM60Z+h99+0rxTmCELRMNHZTnw6pE6cYWPA3b6kXosLWyffiqoZyDZd AppW1EwUcYNggaraPOeDagwsEro7oZ7S1F/b+77bhPa+yIDuadNhPmS4nPDZFfYPXDSD 3lnA== 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=rDKOyGAm4Hfn0xKj2sKop7XrdFnaeTyOP8Au4+yNM8Y=; b=PCvqAUaxcGl+kRamR9P5LBMdvgiOVF8Y1FvhaCLHX+xKrRmD3Ey6rZfFzaPW4+k62h e9+Y34jaRcnv7NLbTs92pOGmNAcSVE7saQ9VtGGxkNC3D7vV4GppgV5xocWOd/B0hBxv o7xaW3kZkUcZCREJ54lGhLaEJMKdybqIxLDXmUGGQlhN7cOpB+9R5j2VbNcwx3EeVaEZ Ebj/fd2N3CW6XCwICPU+X0hwWWtmy1vn30fHGMvtyBdHySrjHGXct/n7Y0EMLFgzr7LI eRPwHZIOzdhbmP1ApJg13vXrjGAWZGEoA5ELeqIocmVrgqD64OO3jSpiMMM1if4cZKhm dR3Q== 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 p15si8862538eda.294.2019.10.01.02.10.26; Tue, 01 Oct 2019 02:10:52 -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 S1733257AbfJAJHP (ORCPT + 99 others); Tue, 1 Oct 2019 05:07:15 -0400 Received: from mail-out.m-online.net ([212.18.0.10]:60603 "EHLO mail-out.m-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729642AbfJAJHO (ORCPT ); Tue, 1 Oct 2019 05:07:14 -0400 Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 46jD1D0RNWz1rgDj; Tue, 1 Oct 2019 11:07:12 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 46jD1C664xz1qqkb; Tue, 1 Oct 2019 11:07:11 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id 0VAN4JYGdG0K; Tue, 1 Oct 2019 11:07:10 +0200 (CEST) X-Auth-Info: F+LKSSdXzI2pXTv5WUICbbnV81SyqaH7V/PX0VhRB3Q= Received: from localhost.localdomain (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Tue, 1 Oct 2019 11:07:10 +0200 (CEST) From: Lukasz Majewski To: Mark Brown , Geert Uytterhoeven Cc: Colin Ian King , linux-spi@vger.kernel.org, krzk@kernel.org, linux-kernel@vger.kernel.org, Lukasz Majewski , kbuild test robot , Julia Lawall , Dan Carpenter Subject: [PATCH] spi: Avoid calling spi_slave_abort() with kfreed spidev Date: Tue, 1 Oct 2019 11:06:57 +0200 Message-Id: <20191001090657.25721-1-lukma@denx.de> 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 Call spi_slave_abort() only when the spidev->spi is !NULL and the structure hasn't already been kfreed. Reported-by: kbuild test robot Reported-by: Julia Lawall Reported-by: Dan Carpenter Signed-off-by: Lukasz Majewski --- This fix applies on: repo: https://kernel.googlesource.com/pub/scm/linux/kernel/git/broonie/spi.git branch: for-5.4 SHA1: 6b04e47b73f2a0d2c330cecca99f8e2cb8f85b34 --- drivers/spi/spidev.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c index 3ea9d8a3e6e8..2c6d4dbeebac 100644 --- a/drivers/spi/spidev.c +++ b/drivers/spi/spidev.c @@ -600,15 +600,16 @@ static int spidev_open(struct inode *inode, struct file *filp) static int spidev_release(struct inode *inode, struct file *filp) { struct spidev_data *spidev; + int dofree; mutex_lock(&device_list_lock); spidev = filp->private_data; filp->private_data = NULL; + dofree = 0; /* last close? */ spidev->users--; if (!spidev->users) { - int dofree; kfree(spidev->tx_buffer); spidev->tx_buffer = NULL; @@ -628,7 +629,8 @@ static int spidev_release(struct inode *inode, struct file *filp) kfree(spidev); } #ifdef CONFIG_SPI_SLAVE - spi_slave_abort(spidev->spi); + if (!dofree) + spi_slave_abort(spidev->spi); #endif mutex_unlock(&device_list_lock); -- 2.20.1