Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp544357ybh; Wed, 18 Mar 2020 04:50:03 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv2sS3BwWf7ZI2blScY5qHnCjL4EhuWxMP4xxl8DL3zbmQ5qmh9bah0p7JmHHWblGSxm/D6 X-Received: by 2002:a05:6808:abb:: with SMTP id r27mr2915564oij.92.1584532203181; Wed, 18 Mar 2020 04:50:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584532203; cv=none; d=google.com; s=arc-20160816; b=tjkhJ00I8H86ttL2cTNeDE5Z+imkeHI+HaKAXOeROnM06NOuPJfo0jbNlDP6BW/Qip pJT0bgM84SilU+iAlC1Ti60t6fNwL9KfNZ+ns1GEiIBzEkH5Xkakr/1oXcHOFvDplYS+ Azdmv7l2dY1Uv/6vUB4NqJY2tn+Ol/qWKkk0nozYDrlfrGwlZbesL+7umpFQiH+I3RJW g8oJPZI1v7zxxswVaikrb86W4CEyIQygD9e+DZnuCAQnH/Wyxk33Pmngdyg/Bi2SEk56 GFadICgkHEijRh3eFgrAfj9R0QheXqPBk5Kii+NnGkXBtRBaD9ktTEQr7x30NtS+ejWM erRQ== 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:cc:to:subject:dkim-signature; bh=khEp2I8LHm4HvDGtASxAHrHxJnhSF2yTyhJnoLBOGY4=; b=zgdh0LynshIBkmCx9MHWbMmb1jfrqXVezP7Z8aQHKo/dO7zdyqwKa1CxEi05Q+gfZE OFHra+LJqHqtO6vwzHnApLlClXANnharMwIxt696O1pH67taDN73/UZbinM6PvEEZYhE gNBXwi2YENkZUHbgV2JzTtzefEtPLosiJV++ZyxAVHlK1axKPJ5c1MkD7gf4HcjLkxrT ZEhTIbViRXtM5TDglQc+KRCFaAOFxjsXoHXbCaJ1CQKQW+rPwu31mInuYbOFnEMidIex azRD0ugdyP1Hbfo77RzBMQb6faBHM7YR9OufD1U0ytAFYwXAhgWtjZyxSGG1+1WCkuCC iM1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xs4all.nl header.s=s1 header.b=iBdzVVXy; 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 l24si2963712otd.199.2020.03.18.04.49.50; Wed, 18 Mar 2020 04:50:03 -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; dkim=pass header.i=@xs4all.nl header.s=s1 header.b=iBdzVVXy; 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 S1727110AbgCRLsv (ORCPT + 99 others); Wed, 18 Mar 2020 07:48:51 -0400 Received: from lb1-smtp-cloud9.xs4all.net ([194.109.24.22]:54977 "EHLO lb1-smtp-cloud9.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726586AbgCRLsu (ORCPT ); Wed, 18 Mar 2020 07:48:50 -0400 Received: from [192.168.2.10] ([46.9.234.233]) by smtp-cloud9.xs4all.net with ESMTPA id EXBkjlhXZfHuvEXBnjap5t; Wed, 18 Mar 2020 12:48:48 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s1; t=1584532128; bh=khEp2I8LHm4HvDGtASxAHrHxJnhSF2yTyhJnoLBOGY4=; h=Subject:To:From:Message-ID:Date:MIME-Version:Content-Type:From: Subject; b=iBdzVVXyhBP2nEUkOIPTZIiBjqoW5rADs11fygjelrCdLqvO6Cfk0nxMrfyDix/Tw OHhOFr71S0sX6aE7kmemwv+pucArj/R6afCPEMybC+qMo8ucl/lxVgFRdDxMBfrPTr i2FTj6qpDHdu6onnD07bEMVYyGMcYItJzNnCnoW9cY4k1bPlzzzh292J/MRV4S4jW2 SePonrJlg+tr6DhZZwdE/oujGLdGlxPBQQDeIYh1ypMUDObrcceGMWxmvK6QRd+FJt cLyDH0Cu8eXOWhDC2Po7LYgRe/BQZ7vgApLxlXl46Dsv67NT8vuBA+VSCCgUcjXSE3 TzTdUIehjBNmg== Subject: Re: [RFC PATCH v3 4/6] media: tegra: Add Tegra210 Video input driver To: Sowjanya Komatineni , thierry.reding@gmail.com, jonathanh@nvidia.com, frankc@nvidia.com, helen.koike@collabora.com, sboyd@kernel.org Cc: linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-clk@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org References: <1581704608-31219-1-git-send-email-skomatineni@nvidia.com> <1581704608-31219-5-git-send-email-skomatineni@nvidia.com> <12a36c2a-593c-e555-d44e-e2e6c4c1a562@nvidia.com> From: Hans Verkuil Message-ID: <5f54c018-5670-8193-7c68-969f9bde92f6@xs4all.nl> Date: Wed, 18 Mar 2020 12:48:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <12a36c2a-593c-e555-d44e-e2e6c4c1a562@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4wfNwp9oXmpvDLlU0y6yBiCGF+VBdilY6z9Cy/qdkxPcn40eWB/r6e9Te3ZFqwW+zTWphUslj27araajeEl8ItMcVphxVvmx1wOq4tJ77CiNTBKx/fCA9i tSRmFih2blN9n/2QWo2mKp6V+5uPegrVxr1k4/Xk2YNsZo3j8qn2EKGuoMUQkR9n1pqkbK+/45VI0fmfqVsqV5WYX9ZGdTVsbprlUS29sQzOqbjscRnE1rxf 0zTUZ556r9bxBGOEcnB//sy7dMF2Hde+ysTYNkl64I5t/S+3BmTpIPKDhTH2tWiYgx5BO6lkA3JSOOWVMu1cOtvSQo9IHEcXYFZKytgpzFxKJLoqjhu+4QNu TtsbR8Fm/pJbeLaPq1d3vdYZHKoPESD4eRiG1/9Bs/7zVLo4vibLr5x60bARuEe/M+aTyk0zwKm2oOm+9JTey4lC/R36GwU6lxN6nwFmi9CiVzqekAtPdZ7z H79/19gQ3cLu0Xopm3k9l187ks9LfJP006rO9SPx9WQ/J4W1D11EPk3NKB/MxL9z6S1611rFy0aiqMgJ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/24/20 5:45 AM, Sowjanya Komatineni wrote: > > On 2/20/20 11:11 AM, Sowjanya Komatineni wrote: >> >> On 2/20/20 5:33 AM, Hans Verkuil wrote: >>> External email: Use caution opening links or attachments >>> >>> >>> (Replying to myself so I can explain this a bit more) >>> >>> On 2/20/20 1:44 PM, Hans Verkuil wrote: >>>>> + >>>>> +static int tegra_csi_tpg_channels_alloc(struct tegra_csi *csi) >>>>> +{ >>>>> +    struct device_node *node = csi->dev->of_node; >>>>> +    unsigned int port_num; >>>>> +    int ret; >>>>> +    struct tegra_csi_channel *item; >>>>> +    unsigned int tpg_channels = csi->soc->csi_max_channels; >>>>> + >>>>> +    /* allocate CSI channel for each CSI x2 ports */ >>>>> +    for (port_num = 0; port_num < tpg_channels; port_num++) { >>>>> +            item = devm_kzalloc(csi->dev, sizeof(*item), GFP_KERNEL); >>>> Using devm_*alloc can be dangerous. If someone unbinds the driver, then >>>> all memory allocated with devm_ is immediately freed. But if an >>>> application >>>> still has a filehandle open, then when it closes it it might still >>>> reference >>>> this already-freed memory. >>>> >>>> I recommend that you avoid using devm_*alloc for media drivers. >>> A good test is to unbind & bind the driver: >>> >>> cd /sys/devices/platform/50000000.host1x/54080000.vi/driver >>> echo -n 54080000.vi >unbind >>> echo -n 54080000.vi >bind >>> >>> First just do this without the driver being used. That already >>> gives me 'list_del corruption' kernel messages (list debugging >>> is turned on in my kernel). > > Will fix in v4 to use kzalloc and also proper release v4l2 to make sure > unbind/bind works properly. > > BTW, tegra vi and csi are registered as clients to host1x video driver. > > So, unbind and bind should be done with host1x video driver "tegra-video" > > cd /sys/devices/platform/50000000.host1x/tegra-video/driver > echo -n tegra-video > unbind > echo -n tegra-video > bind This still crashes with v4, at least if I am streaming with v4l2-ctl --stream-mmap. Is that known? It's not a big deal at this moment, just want to know if this will be looked at later. Regards, Hans > >>> >>> Note that this first test is basically identical to a rmmod/modprobe >>> of the driver. But when I compiled the driver as a module it didn't >>> create any video device nodes! Nor did I see any errors in the kernel >>> log. I didn't pursue this, and perhaps I did something wrong, but it's >>> worth taking a look at. >>> >>> The next step would be to have a video node open with: >>> >>> v4l2-ctl --sleep 10 >>> >>> then while it is sleeping unbind the driver and see what happens >>> when v4l2-ctl exits. >>> >>> Worst case is when you are streaming: >>> >>> v4l2-ctl --stream-mmap >>> >>> and then unbind. >>> >>> In general, the best way to get this to work correctly is: >>> >>> 1) don't use devm_*alloc >>> 2) set the release callback of struct v4l2_device and do all freeing >>> there. >>> 3) in the platform remove() callback you call media_device_unregister() >>>     and video_unregister_device(). >> Reg 3, in current patch, media_device_unregister is called in >> host1x_video_remove >> video_unregister_device happens during host1x_video_remove -> >> host1x_device_exit -> tegra_vi_exit -> tegra_vi_channels_cleanup >> >>> It's worth getting this right in this early stage, rather than fixing it >>> in the future. >>> >>> Regards, >>> >>>          Hans