Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8048657ybn; Tue, 1 Oct 2019 02:19:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzfMC/KkJ7A8eK4fwf1Bsl4hYqy/xzOQx4xotSgoI/49PVZXloBGkRb9XsNW7p+e7ssK84 X-Received: by 2002:a17:906:d79b:: with SMTP id pj27mr13806778ejb.148.1569921554565; Tue, 01 Oct 2019 02:19:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569921554; cv=none; d=google.com; s=arc-20160816; b=lUJYps2433wZAxxsVLs6NoyjlZr1/ldDYfCOVhD4sEnOmj9t45lk+ip/0GWpCqdHQA 6TmXpkxl2ogTpNa5fDyD5vnZMV8QV8Q8S/GXvjAweruW9taAChCh9hK7WVX11gBPAWLC WLPlkIQIsUFDeKS6PIvuzM/PkeQqOOol1/OV3hqhULpEkaURtOVD4eu0BPmALolK26Nw OeRad97MvkbYcRHCL+cj7k9/qpAIEpzfQQ/gD74mcSovHRgYx1AyttAnlkIRGrovbE+h LL53dK3fcNkpmbpTv1Kq7RxCZu1menDOYJych+U7apOB3fP5+/o0rLOnLTgY8g/Nrpcn bRzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=/icWJGEb8mzT5dGk0n3CZD6I5aQgqmHlkE413k8oPWE=; b=GRKK5ZC4OirrD6cViiYDWoPYQHKzUBLW5LTH0hI8reSnuYklAzMwdvI0V6g25oA9rR AHBKuuxk/JLxp50SH2cwM1qRJ0C0bEx0osIyQ8eAJirspAggNIJLOy0Vepc54dOLDLRS nnWsFLH9alGVrUsrIBdZgpXxcSm3ABYTarPISChRBd1EWoYJVCQQUGY/OdrXQHWqxkLo 8df2gzGPfYbHOnCaWLi49ZZ54xpk7HTCEYpGeTyvGukwlYCwuYRl4ykh45rG4KlGCDu+ sUvjrq1U/szOk76GzIDolZOssxACFOsduMC/c+PRLHplwyFHPQqfcQqm3wHgOCLGGPkq 4q+Q== 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 a3si9523878edc.75.2019.10.01.02.18.50; Tue, 01 Oct 2019 02:19:14 -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 S2387492AbfJAJP3 (ORCPT + 99 others); Tue, 1 Oct 2019 05:15:29 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:39965 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733274AbfJAJP2 (ORCPT ); Tue, 1 Oct 2019 05:15:28 -0400 Received: by mail-ot1-f66.google.com with SMTP id y39so10901143ota.7; Tue, 01 Oct 2019 02:15:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/icWJGEb8mzT5dGk0n3CZD6I5aQgqmHlkE413k8oPWE=; b=eD1HbmPWdSkHCunVONDNge7u0nJ1lYramhT/VJv1U5bJxxIttZWNgfyIUNRaCffY+u RrZNDheqyDq4pKZOjD2R313fL6wboFO1PdYqyKEyx9SPjTe0viFu6KwszMAwRaEsLBl/ VD8y7AIfkn7cOmD2XjA1AESrX7gLvGQf88XSIX55bto6EhkaLk6Y9fsApM3+UYgyU2yf ITg3R93l3STJqy3vpTRgDkTNHIvjX4TuE2/BHXmfBXgWQcVs8yqyvIcKEfjDpY6k52s3 7j1bx3AHTjT8TFpqR4IIgyDjpsasx3C81LqsJfxz0T8ZDHX7oNJGKr+xU4JE5I2CPRi1 fcXg== X-Gm-Message-State: APjAAAXAIrTjMKl0LheAWkkRlvmopK1MZC2ZCBKKJuCl51yPP6o/73oC VZiAEDkSTSg2hlfVqSwXK2w2pu47+3PcREDtbpw= X-Received: by 2002:a9d:730d:: with SMTP id e13mr16379131otk.145.1569921328021; Tue, 01 Oct 2019 02:15:28 -0700 (PDT) MIME-Version: 1.0 References: <20191001090657.25721-1-lukma@denx.de> In-Reply-To: <20191001090657.25721-1-lukma@denx.de> From: Geert Uytterhoeven Date: Tue, 1 Oct 2019 11:15:16 +0200 Message-ID: Subject: Re: [PATCH] spi: Avoid calling spi_slave_abort() with kfreed spidev To: Lukasz Majewski Cc: Mark Brown , Colin Ian King , linux-spi , Krzysztof Kozlowski , Linux Kernel Mailing List , kbuild test robot , Julia Lawall , Dan Carpenter Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Lukasz, On Tue, Oct 1, 2019 at 11:07 AM Lukasz Majewski wrote: > 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 Thanks for your patch! > --- 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; bool? > > mutex_lock(&device_list_lock); > spidev = filp->private_data; > filp->private_data = NULL; > + dofree = 0; Why not initialize it at declaration time? > > /* 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); Can spidev->spi be NULL, if spidev->users != 0? > #endif > mutex_unlock(&device_list_lock); Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds