Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5207827rdb; Wed, 13 Dec 2023 01:58:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IFl6YAyJ4F9+AaAOp6jyrgiSwE91kAfjWKPafB5cnK7L5Luo6ZIX41Q+Z7d0nYxnhULJeYS X-Received: by 2002:a05:6871:4390:b0:1fb:75c:3fe9 with SMTP id lv16-20020a056871439000b001fb075c3fe9mr10874893oab.73.1702461537534; Wed, 13 Dec 2023 01:58:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702461537; cv=none; d=google.com; s=arc-20160816; b=OpzYcPZzODzGpw5x7VO0owFFtzHlrQnXP7MFt6d/Nmm6DgpjWmp8tCpA9I2fPXwjle 9boeCaxVilUez9hJrGkliuqeTcZQdTDUFhElLHJu8gEJwF+x5hm8lLvWzPqgr0RoUQVB 40Eom4oEsEh6c+5O6sv8cv5foyTUuNwoU4tFtgIjsWkL6oY0IKlloeuQOgHmHC5utr9c 5nRPlFMoAxfJ7/ZsqBeN7y9INmIeuoM/OcxWtu201Z2IzZR6udsYepyHwpl62dNf/2H9 CsO0z6+lCaqC6jEXrXNMkj3gB0SFR4xMM6QWZcLwIxQQiNtbKYdoiYCccoV1lC+t4HBz E2hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=L4p/dpuozdWaMdW0qLR68U+LmLkdcQ0lDRAfE9DbvgY=; fh=YksymLiHJalAHbzfcejKopU7TEnZOTBbALGj6OfYZpc=; b=qSEqDm5MEzCHGSwFt+4zjqVurdIBYVMbp4aOv79g7E3qZtt7PRV0LmCkjyuKw5wt5v NX0JPNrO/YNMWccoWsC+ru2STTXJObnMbkMNp6xhV5XAycqIGLQwOzBbrRdPvGHNx+gk zGaOw5K4YGWJnpUSdkovU8aHGjMLXGNPtTiog2CVUaD2iAz7BinSGdPWZN1YDp5F7Aql x+3RxVZilN7wZLj2oZ08jh4RDw/6fs02X9GIvH21jA7FxI4n+spPS0f8adC01RaVCog8 b7SwuXIdaEneM8PPTIQol6u7UL5ONga4OApsbWfn9M+4HnLdqOJbumu3FSBWmDL/OBiu dKOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ClCGkiUO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id j8-20020a635948000000b00578ca217740si8913606pgm.711.2023.12.13.01.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 01:58:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ClCGkiUO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id B2AD6804A4F5; Wed, 13 Dec 2023 01:58:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235105AbjLMJ6j (ORCPT + 99 others); Wed, 13 Dec 2023 04:58:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232663AbjLMJ6i (ORCPT ); Wed, 13 Dec 2023 04:58:38 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50B5A83; Wed, 13 Dec 2023 01:58:44 -0800 (PST) Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id E19386CF; Wed, 13 Dec 2023 10:57:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1702461477; bh=JoJj/ykH0cPZRaBJ01vpWhfVB89teGr3YCkf7ZkjkBM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ClCGkiUOsI5Xe9NfB+qY7rWUtusoLoTo4VtEjyCcz47GrfEFzJFLdDzHqs6bRtfuS q7pBJh8iWxmS/m2HMLS+kRWE2HxA7t/5o1whiv48zLIWRxx8Yzh4B3B94qQNKwCJVG vJegemlkP9RF1WOweAqa15z1Tp97GQsLMNTSqYMw= Date: Wed, 13 Dec 2023 11:58:49 +0200 From: Laurent Pinchart To: Sakari Ailus Cc: Arnd Bergmann , Arnd Bergmann , Mauro Carvalho Chehab , Nathan Chancellor , Jacopo Mondi , Hans Verkuil , Nick Desaulniers , Bill Wendling , Justin Stitt , Hans de Goede , Tomi Valkeinen , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] media: i2c: mt9m114: add CONFIG_COMMON_CLK dependency Message-ID: <20231213095849.GA2191@pendragon.ideasonboard.com> References: <20231212213625.3653558-1-arnd@kernel.org> <97a826ab-cd68-4494-884e-f7bd512a7bef@app.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 13 Dec 2023 01:58:54 -0800 (PST) On Wed, Dec 13, 2023 at 09:10:19AM +0000, Sakari Ailus wrote: > Hi Arnd, > > On Wed, Dec 13, 2023 at 09:39:01AM +0100, Arnd Bergmann wrote: > > On Wed, Dec 13, 2023, at 09:09, Sakari Ailus wrote: > > > On Tue, Dec 12, 2023 at 10:18:04PM +0100, Arnd Bergmann wrote: > > >> From: Arnd Bergmann > > >> > > >> With clang-16, building without COMMON_CLK triggers a range check on > > >> udelay() because of a constant division-by-zero calculation: > > >> > > >> ld.lld: error: undefined symbol: __bad_udelay > > >> >>> referenced by mt9m114.c > > >> >>> drivers/media/i2c/mt9m114.o:(mt9m114_power_on) in archive vmlinux.a > > >> > > >> Avoid this by adding a Kconfig dependency that avoids the broken build. > > > > > > This sounds like an odd way to fix an issue with udelay(). On which arch > > > does it happen? Wouldn't it be better to fix the udelay() problem in the > > > source? > > > > > > A quick check reveals there are about 2400 files using udelay. > > > > I observed this on arm, but same sanity check exists on arc, m68k, > > microblaze, nios2 and xtensa, all of which try to discourage > > overly large constant delays busy loops. On Arm that limit is > > any delay of over 2 miliseconds, at which time a driver should > > generally use either msleep() to avoid a busy-loop, or (in extreme > > cases) mdelay(). > > > > I first tried to rewrite the mt9m114_power_on() function to > > have an upper bound on the udelay, but that didn't avoid the > > link error because it still got into undefined C. Disabling > > the driver without COMMON_CLK seemed easier since it already > > fails to probe if mt9m114_clk_init() runs into a zero clk. > > > > Maybe we could just fall back to the soft reset when the > > clock rate is unknown? > > The datasheet says the input clock range is between 6 MHz and 54 MHz. We > could check that, and return an error if it's not in the range. The rate is > needed for other reasons, too, and the sensor is unlikely to work if it's > (more than little) off. > > I wonder if this could address the Clang 16 issue, too? I'd replace > udelay() with fsleep() in any case, and at the very least Clang should be > happy with this. I'm fine with both of those changes. > > diff --git a/drivers/media/i2c/mt9m114.c b/drivers/media/i2c/mt9m114.c > > index 0a22f328981d..88a67568edf8 100644 > > --- a/drivers/media/i2c/mt9m114.c > > +++ b/drivers/media/i2c/mt9m114.c > > @@ -2092,6 +2092,7 @@ static void mt9m114_ifp_cleanup(struct mt9m114 *sensor) > > > > static int mt9m114_power_on(struct mt9m114 *sensor) > > { > > + long freq; > > int ret; > > > > /* Enable power and clocks. */ > > @@ -2104,9 +2105,10 @@ static int mt9m114_power_on(struct mt9m114 *sensor) > > if (ret < 0) > > goto error_regulator; > > > > + freq = clk_get_rate(sensor->clk); > > + > > /* Perform a hard reset if available, or a soft reset otherwise. */ > > - if (sensor->reset) { > > - long freq = clk_get_rate(sensor->clk); > > + if (sensor->reset && freq) { > > unsigned int duration; > > > > /* -- Regards, Laurent Pinchart