Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp704900ybl; Fri, 10 Jan 2020 05:27:45 -0800 (PST) X-Google-Smtp-Source: APXvYqwcDsfA4WagcMo6Fip19JOo37+MZULNRLnCS/bY6hjxciBJhCqxlJ5Y2hLbKFl8DC85nmX7 X-Received: by 2002:aca:ad47:: with SMTP id w68mr2143388oie.63.1578662865022; Fri, 10 Jan 2020 05:27:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578662865; cv=none; d=google.com; s=arc-20160816; b=CUl4J/OLkulgVXR1Fp+4K+ahPpajOCXyWc73skF3W3R7uk5Rzk9xOSfZYDeb6Msu9D ysTCMFSIuOuHYOysFdVzT4fx1PSM5wkk2c++RJjQYPcr4BPl5Jeg9hURhPYQ/p8Xbg42 nWathnWnl+5Qj+qAbY0Xj3eve7jDI3e+6q+c54+Qofkl1eqmAnLI3++2Nv3Q6qyEgbyl UEAaPO/MDpD8s+zWZs+NQVVNcg4RSNT0XIOaZtiZoZAn2H91+GJWmgI5h6vHLWub08PR jKoUeCRan7JJXrTycg1v6AcUbQjeYKYFvelyItfmgD2s3G9J0uw1Z5Df+To4DoYOFjOP lRUA== 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=I0b7s/xDqtbd60FacQFIRFFagV1Bh2XVzbaw6GJ8UFk=; b=XzJbTiZoyBUFzEQTlp8OUGDwfAEtxXwZAbePDppkwr2aaaqdXQq2d19rvQ4PMrG/n0 fAYYXIlmdX45+OGSfjjj5BmuJg8PUDU/kmEQeg35uHFmIMj4snBb79zFAjFzFjfuwqd3 aRkvpkR4+Dyg3TA37dwizz0B7CoXaoKlrV+apSCg/PRYrO42fyAL9wqLsYmC0p5AYoZl g+kqb5ZNGSOhqLH0MficUnFrPqgsFTlERgDf+zwcRIENNHwmE6x2sxqml4aklMD1IYrH qUZORIFDxmUsF9Z8y66YP7u0/LhqUiO1r8Om2npI0IJif8xUdqW7DdfRvuSiMWR3lPyc LqAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xs4all.nl header.s=s1 header.b="TTtT0/u+"; 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 w19si1273844otj.209.2020.01.10.05.27.33; Fri, 10 Jan 2020 05:27:45 -0800 (PST) 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="TTtT0/u+"; 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 S1727784AbgAJNZ0 (ORCPT + 99 others); Fri, 10 Jan 2020 08:25:26 -0500 Received: from lb2-smtp-cloud8.xs4all.net ([194.109.24.25]:41139 "EHLO lb2-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727358AbgAJNZZ (ORCPT ); Fri, 10 Jan 2020 08:25:25 -0500 Received: from [IPv6:2001:420:44c1:2577:c967:e1d3:183a:b8ef] ([IPv6:2001:420:44c1:2577:c967:e1d3:183a:b8ef]) by smtp-cloud8.xs4all.net with ESMTPA id puHrin9xDpLtbpuHuiQmSe; Fri, 10 Jan 2020 14:25:23 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=s1; t=1578662723; bh=I0b7s/xDqtbd60FacQFIRFFagV1Bh2XVzbaw6GJ8UFk=; h=Subject:To:From:Message-ID:Date:MIME-Version:Content-Type:From: Subject; b=TTtT0/u+HRhWOQa06QDndrU0bUEOOnpgZ7+dEC97BkRPFIGB6+mexFpX5KgD0Ycg7 yhQzvpBQhpk2DygTF4OkK7SbCzkIEdbt1VBG6UrD+kwFD6l10FwZudPsgW7v4eMGeL aYwHyNPBtNy6/lyBAFseDupjlwYKHL69gvkN/Cq4uYQTv02WDFPYe6/H3/nZ+1y+tA BALkMj/5GvNS1nAx0I4g/1Vkw1rgqgcm08uw2jwao9fUsMlB844kKhFq4HAFqE21zy nTRdmkh4N365san1LzaN8h2TVUGaY8Hytm1MaugFO+7c4Ri1RfYmfqNAU0fotrD5oM l7dFQzn+02NNg== Subject: Re: [PATCH] staging/vc04_services/bcm2835-camera: distinct numeration and names for devices To: Michael Kupfer , eric@anholt.net, wahrenst@gmx.net, bcm-kernel-feedback-list@broadcom.com, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, mchehab+samsung@kernel.org, linux-media@vger.kernel.org Cc: gregkh@linuxfoundation.org, f.fainelli@gmail.com, rjui@broadcom.com, sbranden@broadcom.com, dave.stevenson@raspberrypi.org, daniela.mormocea@gmail.com, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, linux-kernel@i4.cs.fau.de, Kay Friedrich References: <20191206085432.19962-1-michael.kupfer@fau.de> From: Hans Verkuil Message-ID: <3db2350b-0a6d-0693-258c-9d47f71c0627@xs4all.nl> Date: Fri, 10 Jan 2020 14:25:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191206085432.19962-1-michael.kupfer@fau.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfBd3XXTXHJXsWfyVxCd2xYnZO0N8s/BDiJigBt9fBzOuvI1qg7Ov9vJHlQwwroeHfDptOn2x6LGe/NF17tiYIHe6IKGtbMu6lyUonjXvZHlMv8StSdIC KjYmD4yv2S6PG8353r9KVWVoWKnWpExFpS00SMNPq5IJsX0GyIHHf370xIlWiBo1uFBPJrF+j9ZsO01XP4FQMp1f6UC1jRrs61fg77hJ1wy4Zgliil7O9MiI pvMz1R6SFwWlhjOzw9WPqyNWo8SWxUYcyyfl2v53V+CvWgwJ5DZG7hUbdZP/qv+bKOk5xyhfl26PIEeuFIG6UMCgRYfGFOYgyV991fAuAVn2Dl9s1kexO+eh tpS7DuSgD76w957xPtmjizhbEK3EmsdZ+k/6hrHyjkRb3KLCufZaCXa92/oMKYXPD3EmQEqcCJAZFxvg1thOoX7sSWbv5i9/KTtAn+VIMvFR58Zn88QVT/xo D8/JfnqE8C4zdH9i2TrB90rHJKxmGPFc91KhbCbQaPjrg38xmbFqJcOEL/n/XHiROQtHdEhKeUmzL+4YZJ3WDWuvUhprcNE6aPBSeDmnpTKkpbqgiCwjsfFx d4HTR0D5GW2x8wmWayKH432z9lI6vqffHTdck7Vrvb7hTmdesfRvgriuI8o4dt6SQuT9nJC9rt7gedvyKw7nsxUw4ODfbr24oLSb/ZkIO0o5i9yK2ZpiaWaF 8xfVbVb8KZVaxBQ4srQRGIc3bE4uizhm3PTr00SnN0xw9EXC01pJoNmd2cDfozvoMO3xwPWME7KAsoFn8WDu/XKTRBI2lN7SShrCVzRTZ7f9CEOO/08TtnON N1dWwwey5LGcCnce6F7Dp2Lmnl+Y2/FYR1WiEk3Ad5N+IsvZOD2DORmv4Xwh12IK0kVRpntnSOLvX7ZLyWK1VfnbCoGLBHMQA04SKM8L6IDC+76awJcUkbxl L/eY2w== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Michael, Kay, On 12/6/19 9:54 AM, Michael Kupfer wrote: > Create a static atomic counter for numerating cameras. > Use the Media Subsystem Kernel Internal API to create distinct > device-names, so that the camera-number (given by the counter) > matches the camera-name. > > Co-developed-by: Kay Friedrich > Signed-off-by: Kay Friedrich > Signed-off-by: Michael Kupfer > --- > .../vc04_services/bcm2835-camera/bcm2835-camera.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c > index beb6a0063bb8..be5f90a8b49d 100644 > --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c > +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c > @@ -60,6 +60,9 @@ MODULE_PARM_DESC(max_video_width, "Threshold for video mode"); > module_param(max_video_height, int, 0644); > MODULE_PARM_DESC(max_video_height, "Threshold for video mode"); > > +/* camera instance counter */ > +static atomic_t camera_instance = ATOMIC_INIT(0); > + > /* global device data array */ > static struct bm2835_mmal_dev *gdev[MAX_BCM2835_CAMERAS]; > > @@ -1870,7 +1873,6 @@ static int bcm2835_mmal_probe(struct platform_device *pdev) > > /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */ > mutex_init(&dev->mutex); > - dev->camera_num = camera; > dev->max_width = resolutions[camera][0]; > dev->max_height = resolutions[camera][1]; > > @@ -1886,8 +1888,9 @@ static int bcm2835_mmal_probe(struct platform_device *pdev) > dev->capture.fmt = &formats[3]; /* JPEG */ > > /* v4l device registration */ > - snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), > - "%s", BM2835_MMAL_MODULE_NAME); > + dev->camera_num = v4l2_device_set_name(&dev->v4l2_dev, > + BM2835_MMAL_MODULE_NAME, > + &camera_instance); > ret = v4l2_device_register(NULL, &dev->v4l2_dev); > if (ret) { > dev_err(&pdev->dev, "%s: could not register V4L2 device: %d\n", > Actually, in this specific case I would not use v4l2_device_set_name(). Instead just use: snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s-%u", BM2835_MMAL_MODULE_NAME, camera); It would be even better if there would be just one top-level v4l2_device used for all the camera instances. After all, there really is just one platform device for all of the cameras, and I would expect to see just a single v4l2_device as well. It doesn't hurt to have multiple v4l2_device structs, but it introduces a slight memory overhead since one would have been sufficient. v4l2_device_set_name() is meant for pci-like devices. And it really is a bit overkill to have it as a helper function. Regards, Hans