Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp117044pxv; Thu, 24 Jun 2021 04:15:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+VkKNW75uFtAbMQz/YrwjtgI5J/cdu4xoZwR6G1nbNIPihXoBoagC6fOn3pe3R0doa3E5 X-Received: by 2002:a02:a688:: with SMTP id j8mr4126745jam.107.1624533305637; Thu, 24 Jun 2021 04:15:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1624533305; cv=pass; d=google.com; s=arc-20160816; b=AGJs1zc8igDucBlqtTY3PvN+9uwQmpzVa+rwX3cCb+yajAnBdYQtD1dYIlkng/f/fQ N/xBCKIrK0tRj/NvpdnO7k/vrPM9OaogolcFJKIcMKlTxgs0Jj1h7SRLxsR3gIkh1qpt 4XH5/Yj55fvYid7XvALcNgfLWHIt1zA2TGCpBpwhAeAEGxgCuIhrh2Ng9FO0ca5AGHdb I/8f0+OQ2aCFDvb4NShIUwEUeTtiEzd2tPToUcD/HEi/s6wFbGLHbheXbJ7k8YP84fox 2eU2atAMrEbYuPhmZ51Ou/DD3ZK4aFZIO1R0fbyseOWe11VGNDaPbi2+wn4UEvE+brTs bfPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=1qzhlrXC0wPeGZ7oSreUo8Do8dTv//1G8zRRIlr3ERI=; b=uFM/5xvvl3x77mGrPONhEurmIwgkUMqi+svrJn1jfbNn0n+aWUVHH+Bd0yXL2qd33S dyWsEJ6OjnCrB+iY+/43Yo3VMYjoYli05OU0/VY/w3Uu9cJz2IIlYqGs0o3O2fn5qCf/ Agfg9jMm2yhlTYNIb4Z+3za8F9FuwClDCjbOrusPzkXGCZ7s9QMsiPuWH/TJ4nw/cKgx JkZ7darGuO/YunC4k3YcQIrC5jAyAfdm5ba9IClsaPMnPQO+q8JGW8KAgT5syPa8KFu1 ZHSSjc6f5WIfc2+ilNfEAYnBAORARneIUKP3W92W2NyZi9+9xf8AGYHL3fbst2EPdIuO 7aOA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@iki.fi header.s=lahtoruutu header.b=OQafcfPY; arc=pass (i=1); 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d16si516085iop.94.2021.06.24.04.14.38; Thu, 24 Jun 2021 04:15:05 -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=@iki.fi header.s=lahtoruutu header.b=OQafcfPY; arc=pass (i=1); 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232372AbhFXLPO (ORCPT + 99 others); Thu, 24 Jun 2021 07:15:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232310AbhFXLPN (ORCPT ); Thu, 24 Jun 2021 07:15:13 -0400 Received: from lahtoruutu.iki.fi (lahtoruutu.iki.fi [IPv6:2a0b:5c81:1c1::37]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A882C061574; Thu, 24 Jun 2021 04:12:54 -0700 (PDT) Received: from hillosipuli.retiisi.eu (dsl-hkibng32-54fb5d-176.dhcp.inet.fi [84.251.93.176]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sailus) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 5DC6E1B001A5; Thu, 24 Jun 2021 14:12:52 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1624533172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1qzhlrXC0wPeGZ7oSreUo8Do8dTv//1G8zRRIlr3ERI=; b=OQafcfPYTuhH956c14NnhD8jFOynZ8GeazG+91DZ7fxkJq9QMwDyT3rqU1ADFzPYzjAj1d XHOb8jM7udyc7irXKwsNXvk7s6F7cjGwP7olkyLKCBEoeYFuczolzISS3zmbsw2KqRF9+0 ZhOHSfuBgniUu/TnU/p/KVG5RycVlp+p0iHW0kqP86Hh8dEiKgHXjBc+O5nPJaww3R4Dlj +aLkowAfW52sKpEhQNMFsVnGtKDzGlhnLBRVUgl4T4LOuv0UjmGw6sa+WYnK6DAi1/Tv3u DvvWpF+8+8kWSSGl4Me5iJhCZxCxAQvXUY0dxkOnEJ14XaEeKZV9/adJ3c9eXA== Received: from valkosipuli.localdomain (valkosipuli.localdomain [IPv6:fd35:1bc8:1a6:d3d5::80:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by hillosipuli.retiisi.eu (Postfix) with ESMTPS id B1B3D634C87; Thu, 24 Jun 2021 14:12:36 +0300 (EEST) Received: from localhost ([127.0.0.1] helo=valkosipuli.retiisi.eu) by valkosipuli.localdomain with esmtp (Exim 4.92) (envelope-from ) id 1lwNHw-00019i-Bt; Thu, 24 Jun 2021 14:12:52 +0300 Date: Thu, 24 Jun 2021 14:12:52 +0300 From: Sakari Ailus To: Mauro Carvalho Chehab Cc: linuxarm@huawei.com, mauro.chehab@huawei.com, Mauro Carvalho Chehab , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Subject: Re: [PATCH 3/5] media: v4l2-flash-led-class: drop an useless check Message-ID: <20210624111252.GL3@valkosipuli.retiisi.eu> References: <20210624093153.GJ3@valkosipuli.retiisi.eu> <20210624115925.357f98b6@coco.lan> <20210624101443.GK3@valkosipuli.retiisi.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210624101443.GK3@valkosipuli.retiisi.eu> User-Agent: Mutt/1.10.1 (2018-07-13) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1624533172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=1qzhlrXC0wPeGZ7oSreUo8Do8dTv//1G8zRRIlr3ERI=; b=GrEOJBOJrl8vL3Xci9So2WG53d3dIPb1LCR1TgL5qjrL0iW03lj99xcZs4um+jBCzPbOZU Lt1GpHF9lRjisn2wsteNKyPE6jn+sU0711MMxophJphnZMpFOhv75zyvY/35XaFDpKQtrH W5ssbibwOrLX0XS8gIYnsu/ieYaVsAouVZO2eQ3ztoA3aZ4xIdvRFFz2w1c+tqaUQlyWbg gQgrhmajuF5l3ZCtxTvPW90nVHpqCq7PqNId1T9/ZreXl6x8iHyqaAKepyHcb7fN2eS5tj Qrdscn/Oh1D/9phkodtn8QGoSB8syh8nPSzoaSIeFArUHlCeyWJkHMzfYH1GlA== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=sailus smtp.mailfrom=sakari.ailus@iki.fi ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1624533172; a=rsa-sha256; cv=none; b=MgRNuuRmSy/ELOy08p5GEckKmc9079X4jO0pI826tGtPj7twSpMQG/Ep3mqvSRZPyTGYgx /N7sxnJWOxtOIJNz6V5y+CkMWW77HT1MnNjPWXpRkBgIcgtB5RQvIvaUuCVAgK7jpUEck7 UVOX94RoW3PJyMGFEIYGiKbSiyr7URudclEvBh4a/ibSj8bI0T9gRn62OMGGMr9lBeKajD 4niHXrG17EOAVP8xCCF5/z3maJQJ1F+C/n4SbEKrzDpAtIGIm+vfOcfVRwNUzQ6DSxvkBJ e3P1AxMaeS5/FjZuGL3zRddZMgWNQsDiJfags13q6r5RI62rE9YKao0Ni1o4Fg== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 24, 2021 at 01:14:43PM +0300, Sakari Ailus wrote: ... > > > On Mon, Jun 21, 2021 at 01:56:47PM +0200, Mauro Carvalho Chehab wrote: > > > > As pointed by smatch: > > > > drivers/media/v4l2-core/v4l2-flash-led-class.c:264 v4l2_flash_s_ctrl() error: we previously assumed 'fled_cdev' could be null (see line 197) > > > > > > > > It is too late to check if fled_cdev is NULL there. If such check is > > > > needed, it should be, instead, inside v4l2_flash_init(). > > > > > > > > On other words, if v4l2_flash->fled_cdev() is NULL at > > > > v4l2_flash_s_ctrl(), all led_*() function calls inside the function > > > > would try to de-reference a NULL pointer, as the logic won't prevent > > > > it. > > > > > > > > So, remove the useless check. > > > > > > > > Signed-off-by: Mauro Carvalho Chehab > > > > --- > > > > drivers/media/v4l2-core/v4l2-flash-led-class.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/media/v4l2-core/v4l2-flash-led-class.c b/drivers/media/v4l2-core/v4l2-flash-led-class.c > > > > index 10ddcc48aa17..a1653c635d82 100644 > > > > --- a/drivers/media/v4l2-core/v4l2-flash-led-class.c > > > > +++ b/drivers/media/v4l2-core/v4l2-flash-led-class.c > > > > @@ -194,7 +194,7 @@ static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c) > > > > { > > > > struct v4l2_flash *v4l2_flash = v4l2_ctrl_to_v4l2_flash(c); > > > > struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; > > > > - struct led_classdev *led_cdev = fled_cdev ? &fled_cdev->led_cdev : NULL; > > > > + struct led_classdev *led_cdev = &fled_cdev->led_cdev; > > > > > > fled_cdev may be NULL here. The reason is that some controls are for flash > > > LEDs only but the same sub-device may also control an indicator. This is > > > covered when the controls are created, so that the NULL pointer isn't > > > dereferenced. > > > > I double-checked the code: if a a NULL pointer is passed, the calls > > to the leds framework will try to de-reference it or will return an > > error. > > > > For instance, those will return an error: > > > > static inline int led_set_flash_strobe(struct led_classdev_flash *fled_cdev, > > bool state) > > { > > if (!fled_cdev) > > return -EINVAL; > > return fled_cdev->ops->strobe_set(fled_cdev, state); > > } > > > > #define call_flash_op(fled_cdev, op, args...) \ > > ((has_flash_op(fled_cdev, op)) ? \ > > (fled_cdev->ops->op(fled_cdev, args)) : \ > > -EINVAL) > > > > No big issue here (except that the function will do nothing but > > return an error). > > > > However, there are places that it will cause it to de-reference > > a NULL pointer: > > > > int led_set_brightness_sync(struct led_classdev *led_cdev, unsigned int value) > > { > > if (led_cdev->blink_delay_on || led_cdev->blink_delay_off) > > return -EBUSY; > > > > led_cdev->brightness = min(value, led_cdev->max_brightness); > > > > if (led_cdev->flags & LED_SUSPENDED) > > return 0; > > > > return __led_set_brightness_blocking(led_cdev, led_cdev->brightness); > > } > > > > So, this is not a false-positive, but, instead, a real issue. > > > > So, if led_cdev/fled_cdev can indeed be NULL, IMO, the right solution would be > > to explicitly check it, and return an error, e. g.: > > > > static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c) > > { > > struct v4l2_flash *v4l2_flash = v4l2_ctrl_to_v4l2_flash(c); > > struct led_classdev_flash *fled_cdev = v4l2_flash->fled_cdev; > > struct led_classdev *led_cdev; > > struct v4l2_ctrl **ctrls = v4l2_flash->ctrls; > > bool external_strobe; > > int ret = 0; > > > > if (!fled_cdev) > > return -EINVAL; > > The approach is correct, but as noted, the check needs to be done later. I checked that the same pattern is used throughout much of the file. I suppose if smatch isn't happy with this instance, it may not be happy with the rest either. Admittedly, the pattern isn't entirely trouble-free, as it requires the parts of the file to be in sync. Addressing this takes probably a few patches at least. -- Sakari Ailus