Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp395412ybk; Wed, 20 May 2020 02:22:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzBDrx6+JSVmmnHx303otYrKShvIbgotIZ/MTLVgd3zWqgnQggQWxbWws2AfhpAmWmbOov X-Received: by 2002:a05:6402:959:: with SMTP id h25mr2445646edz.287.1589966555506; Wed, 20 May 2020 02:22:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589966555; cv=none; d=google.com; s=arc-20160816; b=FOxh1AYDe4CtZ9FPaHXtfzOcLNV/QPEBzAnj1x4sufqotO/wJohSAtmgWq9SNn4gky N+lp6aDmUNc16TZY+huk81TkWOmMzX3fn9NemwPx5JFlV+HoCVjMjuJ1qIunVn1nu+3B LrbOOSQsx0WbDctZXkiBinMF/k5yo1+iLzdqFb+UAl8lW9eL3ZCwOy35UYqyxuGD1DRj qv+r/tDnNups9qCqhHRmvWXAV2mHzVViuopznmGGgvZM7hn9zDsoY+8oSe0H9yQAcFS+ NsrWzF4hiNcifqlcsLqKJZI3A8Ztgw4eaBdbfV/bP/LiLAu+OOFPD8R99EIsaph0j9pa 9q2w== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=SBboUW4Q1RwNVwHrHpiX+mZpvBIQ6oNqpLWfQmZ8qcQ=; b=VOuPCbRLaxAnT6ambCl8fh1JK6aPvy4WuLuwTo26aBPqy0WmDXYmXFt9PpWpo8NOSS S0PS5noOcBF0zTxieu4WSbKvq6ZwK6ZaWMlGwKYgZsCA9Khl2X01KlpTtF9fYbSrNN9p jF4rkePPAsePpf5LU64G67eTxp9XvYGY2EVPZbKGyI7WtLfinbA/AcMJ5rHg24OpcSdt EekA6xVJCBp9WoKSSzBiN3/inpxicI81hLdIEb66VQbiZTUhwWTWPZ5ogFdywlyrSAFT xOV0oLEZHU6T38sWkSmp3AAYfEVjMjsc6t5M9JO/8Tm0TOGxM4oi67sBDG+MqiQ/5nLs LmvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=pbqiPc73; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p1si1482804ejr.296.2020.05.20.02.22.12; Wed, 20 May 2020 02:22:35 -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=@ti.com header.s=ti-com-17Q1 header.b=pbqiPc73; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726570AbgETJSe (ORCPT + 99 others); Wed, 20 May 2020 05:18:34 -0400 Received: from lelv0142.ext.ti.com ([198.47.23.249]:53774 "EHLO lelv0142.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726224AbgETJSe (ORCPT ); Wed, 20 May 2020 05:18:34 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 04K9ITRx019142; Wed, 20 May 2020 04:18:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1589966309; bh=SBboUW4Q1RwNVwHrHpiX+mZpvBIQ6oNqpLWfQmZ8qcQ=; h=Subject:To:References:From:Date:In-Reply-To; b=pbqiPc736FZChkgti37Lwq7+1C4WE+ye9QNHEOsW4Q1jjYXv3tRATlKODXbxZUG4Y TfRF7CFfp4RXgnfBLy5oFiyg/tP5ESJ0EEoG5Kpw8HX2lKplYmkeiP2GbR5Pi7jfKj L0RsPGViYOAfF7e2lWtCODsFetXVzP9y0aocbopw= Received: from DFLE111.ent.ti.com (dfle111.ent.ti.com [10.64.6.32]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 04K9IThJ078989 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 20 May 2020 04:18:29 -0500 Received: from DFLE106.ent.ti.com (10.64.6.27) by DFLE111.ent.ti.com (10.64.6.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Wed, 20 May 2020 04:18:28 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Wed, 20 May 2020 04:18:28 -0500 Received: from [192.168.2.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 04K9IROx066431; Wed, 20 May 2020 04:18:27 -0500 Subject: Re: Bad kfree of dma_parms in v5.7-rc5 To: Marek Szyprowski , Linux Media Mailing List , Mauro Carvalho Chehab , Ulf Hansson , LKML References: From: Tomi Valkeinen Message-ID: Date: Wed, 20 May 2020 12:18:26 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Marek, On 20/05/2020 12:13, Marek Szyprowski wrote: > Hi Tomi, > > On 20.05.2020 11:00, Tomi Valkeinen wrote: >> Commit 9495b7e92f716ab2bd6814fab5e97ab4a39adfdd ("driver core: >> platform: Initialize dma_parms for platform devices") v5.7-rc5 causes >> at least some v4l2 platform drivers to break when freeing resources. >> >> E.g. drivers/media/platform/ti-vpe/cal.c uses >> vb2_dma_contig_set_max_seg_size() and >> vb2_dma_contig_clear_max_seg_size() to manage the dma_params, and >> similar pattern is seen in other drivers too. >> >> After 9495b7e92f716ab2, vb2_dma_contig_set_max_seg_size() will not >> allocate anything, but vb2_dma_contig_clear_max_seg_size() will still >> kfree the dma_params. >> >> I'm not sure what's the proper fix here. A flag somewhere to indicate >> that vb2_dma_contig_set_max_seg_size() did allocate, and thus >> vb2_dma_contig_clear_max_seg_size() must free? >> >> Or drop the kzalloc and kfree totally, if dma_params is now supposed >> to always be there? > > Thanks for reporting this issue! > > Once the mentioned commit has been merged, the code should assume that > the platform devices does have a struct dma_params allocated, so the > proper fix is to alloc dma_params only if the bus is not a platform bus: > > if (!dev_is_platform(dev) && !dev->dma_parms) { >     dev->dma_parms = kzalloc(sizeof(*dev->dma_parms), GFP_KERNEL); > > same check for the free path. There is also "amba: Initialize dma_parms for amba devices". And the commit message says PCI devices do this too. Guessing this based on the device type doesn't sound like a good idea to me. Tomi -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki