Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp271094ybm; Thu, 28 May 2020 02:17:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygD04oTweruZMBARz7RNFgMAlPp/zkIqBc153XhSJvp1l+XX6gqgGfo7H51Fl0gFTppOhn X-Received: by 2002:a17:906:dc2:: with SMTP id p2mr2089899eji.212.1590657457542; Thu, 28 May 2020 02:17:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590657457; cv=none; d=google.com; s=arc-20160816; b=mvWRFLiTJmh0IF9q1ONhcHQ8eHnNsMqcanCZW49BR+a0Y5mwJr+IIMiaaJjfoo7TkF bURIx+1+qjn49kWX00rAJliHW+B+Ejn3/puZp52hW8O6tA1qdGMPzln1ZLprlHZaFH1/ ZdkVa3WyVXjMRrX0wLI2qQgUCaYk6qMlm29HED8axsJLmMK0ccHnz2KodzBhWbfzUtLp oLEvGYDF4oYFlnLDLB25K9/QqsUIJUXweoHb1/J1Xq9eL0sMrw/jzyeFYgcK0bG6ZLBn MaHoTLyG0hdOM5kDY7x1CPyqFHzs5TPdzl1Le6QnuJez1J/0lDrBC8/gUvpkA6Vd3sLS l1tQ== 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:dkim-signature; bh=/bUPBRUsoGA3duyrH2TeZMw5+oOeqgZqPYVv5N0Bp8E=; b=NucZXjip4T/9GnJyQ5eFDOdQBgdfOpqnIUqePY+zyJYZZYXmCUgjMjdWAnFGwC2lRs WWHFcTK16p/XIjk8DE94lfb5v2lDxydhXUtIY9RQsVUu7pjr5cY4cikmPsgAhVmGH3el Kt2zdIfsRQMjyxD9Ef9F49SZN6OiTdlyVa4WHOD7qpxUoBE6I7ztbg/C9S9XbyLdBw2m FpSko5+3Y7fpD+8r2KEFp4IaYSAvwHSMKf0CeNZcMnzP35HvAStEXFqUgCfAU75/cz0S +S764WSPhVouEzjHZeq5vJkYdlJ/yxyX0bzLZaybeciSpy8vdPMejgKQVBfp76Zs8riu KGmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ne//iH64"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h1si2973542edq.86.2020.05.28.02.17.14; Thu, 28 May 2020 02:17:37 -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; dkim=pass header.i=@linaro.org header.s=google header.b="Ne//iH64"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728189AbgE1JO5 (ORCPT + 99 others); Thu, 28 May 2020 05:14:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728129AbgE1JO4 (ORCPT ); Thu, 28 May 2020 05:14:56 -0400 Received: from mail-ua1-x944.google.com (mail-ua1-x944.google.com [IPv6:2607:f8b0:4864:20::944]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAAB9C05BD1E for ; Thu, 28 May 2020 02:14:55 -0700 (PDT) Received: by mail-ua1-x944.google.com with SMTP id 14so9397608uaq.11 for ; Thu, 28 May 2020 02:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/bUPBRUsoGA3duyrH2TeZMw5+oOeqgZqPYVv5N0Bp8E=; b=Ne//iH640h/EEBEtqoCGfuf9pMzYa08gUSFPet3nUiWCMFf0CC/Gr2oVUm+Mf1G5pW 7I+c1si80x3o3epEQxzm7aObeVrftr8ivjyXsU0NJLnA6nlvfoZTIVtA94ZOOXhi8eY2 KaVs/FyPxbO3ByDFxkdYun2tB6/rHrXt7tlFKQzbSED4KznRDQMndxc/5jEe/eS9oibp DphU8kmMLxd4jpPNExEYWjWzLiyT4OUBFwHyJj5kvH12rkSlaK7khY7SfOshYCYl61AT yiPZjzm1mK5EqW9n3cipObQ28qNzKmCAS+U3Jml+uAqujflKxeH72CxxBdNIKtd0O2Bj W7Xg== 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=/bUPBRUsoGA3duyrH2TeZMw5+oOeqgZqPYVv5N0Bp8E=; b=RPr4/VdwUFOikd9IiiwLJMIRphn4l/IW6lHVjxav5J3cVG/xEU4qUnuGUnrTkpCsVF b+a/73oVEKzKOjdX8WlHRBoo4vYAfilUZrk0KBk3iAuesJo3ibBkBp/cf52Cz3oQRi8x HitQTnObY7JafHf0npbE+mHKd2R+08XbFPPUjIDC/wV0c1JzbZS5mX8Q2StR9Zm01CAt P/YvuvRh772p7TLoKWllcWksSOQCGuoXMJaHqdQ295zqtSfiySr86WBaJg4foYOGlc0V o3O1A2/DsHei2mcUyrn8W1PRYcoqb5KHw/MBKX42fnsv1M2xUv96IgA4tQJzL05ynNGo xBaQ== X-Gm-Message-State: AOAM533BRkfXjIGF8FRR4vG0ZzjzXtJhWlGgBA2AO/FSXCTp8vCaceCi /oDzvCd4Y8zUGt++CDfjywKaR5fENxJfEvchwQAFrGySzAg= X-Received: by 2002:ab0:13f2:: with SMTP id n47mr1188594uae.129.1590657294933; Thu, 28 May 2020 02:14:54 -0700 (PDT) MIME-Version: 1.0 References: <20200527082334.20774-1-tomi.valkeinen@ti.com> In-Reply-To: <20200527082334.20774-1-tomi.valkeinen@ti.com> From: Ulf Hansson Date: Thu, 28 May 2020 11:14:18 +0200 Message-ID: Subject: Re: [PATCHv2] media: videobuf2-dma-contig: fix bad kfree in vb2_dma_contig_clear_max_seg_size To: Tomi Valkeinen Cc: Linux Media Mailing List , Mauro Carvalho Chehab , Marek Szyprowski , LKML , "# 4.0+" 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 On Wed, 27 May 2020 at 10:23, Tomi Valkeinen wrote: > > Commit 9495b7e92f716ab2bd6814fab5e97ab4a39adfdd ("driver core: platform: > Initialize dma_parms for platform devices") in v5.7-rc5 causes > vb2_dma_contig_clear_max_seg_size() to kfree memory that was not > allocated by vb2_dma_contig_set_max_seg_size(). > > The assumption in vb2_dma_contig_set_max_seg_size() seems to be that > dev->dma_parms is always NULL when the driver is probed, and the case > where dev->dma_parms has bee initialized by someone else than the driver > (by calling vb2_dma_contig_set_max_seg_size) will cause a failure. > > All the current users of these functions are platform devices, which now > always have dma_parms set by the driver core. To fix the issue for v5.7, > make vb2_dma_contig_set_max_seg_size() return an error if dma_parms is > NULL to be on the safe side, and remove the kfree code from > vb2_dma_contig_clear_max_seg_size(). > > For v5.8 we should remove the two functions and move the > dma_set_max_seg_size() calls into the drivers. > > Signed-off-by: Tomi Valkeinen > Fixes: 9495b7e92f71 ("driver core: platform: Initialize dma_parms for platform devices") > Cc: stable@vger.kernel.org Thanks for fixing this! However, as I tried to point out in v1, don't you need to care about drivers/media/platform/s5p-mfc/s5p_mfc.c, which allocates its own type of struct device (non-platform). No? Kind regards Uffe > --- > > Changes in v2: > * vb2_dma_contig_clear_max_seg_size to empty static inline > * Added cc: stable and fixes tag > > .../common/videobuf2/videobuf2-dma-contig.c | 20 ++----------------- > include/media/videobuf2-dma-contig.h | 2 +- > 2 files changed, 3 insertions(+), 19 deletions(-) > > diff --git a/drivers/media/common/videobuf2/videobuf2-dma-contig.c b/drivers/media/common/videobuf2/videobuf2-dma-contig.c > index d3a3ee5b597b..f4b4a7c135eb 100644 > --- a/drivers/media/common/videobuf2/videobuf2-dma-contig.c > +++ b/drivers/media/common/videobuf2/videobuf2-dma-contig.c > @@ -726,9 +726,8 @@ EXPORT_SYMBOL_GPL(vb2_dma_contig_memops); > int vb2_dma_contig_set_max_seg_size(struct device *dev, unsigned int size) > { > if (!dev->dma_parms) { > - dev->dma_parms = kzalloc(sizeof(*dev->dma_parms), GFP_KERNEL); > - if (!dev->dma_parms) > - return -ENOMEM; > + dev_err(dev, "Failed to set max_seg_size: dma_parms is NULL\n"); > + return -ENODEV; > } > if (dma_get_max_seg_size(dev) < size) > return dma_set_max_seg_size(dev, size); > @@ -737,21 +736,6 @@ int vb2_dma_contig_set_max_seg_size(struct device *dev, unsigned int size) > } > EXPORT_SYMBOL_GPL(vb2_dma_contig_set_max_seg_size); > > -/* > - * vb2_dma_contig_clear_max_seg_size() - release resources for DMA parameters > - * @dev: device for configuring DMA parameters > - * > - * This function releases resources allocated to configure DMA parameters > - * (see vb2_dma_contig_set_max_seg_size() function). It should be called from > - * device drivers on driver remove. > - */ > -void vb2_dma_contig_clear_max_seg_size(struct device *dev) > -{ > - kfree(dev->dma_parms); > - dev->dma_parms = NULL; > -} > -EXPORT_SYMBOL_GPL(vb2_dma_contig_clear_max_seg_size); > - > MODULE_DESCRIPTION("DMA-contig memory handling routines for videobuf2"); > MODULE_AUTHOR("Pawel Osciak "); > MODULE_LICENSE("GPL"); > diff --git a/include/media/videobuf2-dma-contig.h b/include/media/videobuf2-dma-contig.h > index 5604818d137e..5be313cbf7d7 100644 > --- a/include/media/videobuf2-dma-contig.h > +++ b/include/media/videobuf2-dma-contig.h > @@ -25,7 +25,7 @@ vb2_dma_contig_plane_dma_addr(struct vb2_buffer *vb, unsigned int plane_no) > } > > int vb2_dma_contig_set_max_seg_size(struct device *dev, unsigned int size); > -void vb2_dma_contig_clear_max_seg_size(struct device *dev); > +static inline void vb2_dma_contig_clear_max_seg_size(struct device *dev) { } > > extern const struct vb2_mem_ops vb2_dma_contig_memops; > > -- > Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. > Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki >