Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8088444ybn; Tue, 1 Oct 2019 03:03:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyR/nv13Dtt8YlXTNu8Z4UoS20sIGDlrPdrbGqt4zGmA49qBQjuQWDjJ7Y+XpqXfsXznYxk X-Received: by 2002:aa7:d750:: with SMTP id a16mr24567222eds.27.1569924226185; Tue, 01 Oct 2019 03:03:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569924226; cv=none; d=google.com; s=arc-20160816; b=YP4LOp5AaatqKNNGKH0S4guRCtEMRwVGg04pH5n62LHLL3QK3as3T/6CwKWvm3apxo AXN5rWg50otqFOG2eVJLLWq2xvDvGScWTI5MvlbYs2GUrRj8bnhNxirwLGsVn6dY+rhg 1OmCtKRGQ6sM8yhyxz70zruK0d+bBn5b4eYrX8+lAcPuKPtzRDAQylhGIy3hzR1hgDiz SfqHkkViTu67AZvrTanWHPFPGTsA3B/6IOChtf81RtGjMRfcBf7ZTlLkGHvi317VzAju hGcwNKuXJVPBrFz+DtWb/1MeaqqaycsQOVPttE9RHbATvd8DkxXPV/a0NZ327l7DeLwD gQaA== 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=faGsizJ3ecBmRT0lC0LHIc1ED5+33ls7KqFDwpGQp1Y=; b=Qp9B6pia35JLjkulpUS9BTjKfde8Gsa2QjjlMy0d56e93UJez+eVadOXPIvhRcODeq 57WSvHSjegbv/Z/hSE83U03Y86hVfILlrvtZi4UiyNQIqLKF3b+mhmAO3xy6T4DI/QEZ aJ/AwOB+/wO3W8yfXnDkpiCoJS0KQyXJUhwCUwT3MhRnsQW1XyS+hrnDcsv7BnMtEpUS 2HRXZDd39D7q0yjZ8BInTEgQcFmPB2blBRsyamAFjQuBxeZlGe1LFmOMvkubleuFaxsu dcvXoseTCnN4fPOo2szh01HYfchmK5X/2fWXFmy2nuvdHXKax/asrdNBfVSZyWws+ofS Bphw== 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 j51si8852509ede.301.2019.10.01.03.03.19; Tue, 01 Oct 2019 03:03:46 -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 S1729923AbfJAKAU (ORCPT + 99 others); Tue, 1 Oct 2019 06:00:20 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:44659 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729579AbfJAKAT (ORCPT ); Tue, 1 Oct 2019 06:00:19 -0400 Received: by mail-ot1-f68.google.com with SMTP id 21so10974419otj.11; Tue, 01 Oct 2019 03:00:19 -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=faGsizJ3ecBmRT0lC0LHIc1ED5+33ls7KqFDwpGQp1Y=; b=fc22cYz14ZLuj+6gUEMxaAyItYCtL/+OMGHN/xCY8SE3ul0KmRozOtLm+G+xPiLNl2 ce/jxsFL8pL121piU+DSXkHOyIDMwP+60BV63HHsHbYXGCqKB8bFJxRnqNKs7mc40eka lyeBQulzXFmc6V0deKK4buLGfV+EyJUlOaBNmLfmkp3vThhSdRaeXIj5+i70K6hJCWtx ROxy5t6M4aaOt7CvUOuemVa37HNB0qChf1SW3ipGWxOPG6P0Lro9F/kqTSdcIZO+5jjT /wTXuePKSZG0RhHE05UBTcZLrQJzFeU0HeXQq9WaidqU+e52DM/Cmm1MLbNXk5UVNTwd sNPg== X-Gm-Message-State: APjAAAU2Rib0sYM4u9A+3CVBloQHOlh0OUa+l3rE8MeS/lskVEQU9puQ 65i9rDKnGFX8NIvOFloIIqm/SmLWVuzeclcJcOw= X-Received: by 2002:a9d:404d:: with SMTP id o13mr17642078oti.39.1569924018857; Tue, 01 Oct 2019 03:00:18 -0700 (PDT) MIME-Version: 1.0 References: <20191001090657.25721-1-lukma@denx.de> <20191001113420.032dbfef@jawa> In-Reply-To: <20191001113420.032dbfef@jawa> From: Geert Uytterhoeven Date: Tue, 1 Oct 2019 12:00:07 +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:34 AM Lukasz Majewski wrote: > > 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 > > > --- 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); > > > > Can spidev->spi be NULL, if spidev->users != 0? > > No, it shouldn't be. > > The "dofree" is only set to true (the spidev->spi == NULL condition is > checked) if there are no references (spidev->users == 0). > > The if (!dofree) prevents from calling spi_slave_abort() when > spidev->spi == NULL and spidev is kfree'd. If spidev->users != 0, the block checking spidev->spi == NULL is never executed, and spi_slave_abort() will be called. I'm wondering if spidev->spi can be NULL if spidev->users is still positive. 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