Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5266837rdb; Wed, 13 Dec 2023 04:09:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHANPox65IYKZaiZIC2Bt5dMsYFyZRRg2KrEPBzp6IRdMhPbSpesNo0Vw7GmFQhh1a03eel X-Received: by 2002:a05:6a00:2286:b0:6ce:4288:f749 with SMTP id f6-20020a056a00228600b006ce4288f749mr5201012pfe.14.1702469349840; Wed, 13 Dec 2023 04:09:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702469349; cv=none; d=google.com; s=arc-20160816; b=I+eFLIcHFxKryzCxr1Dg2YydgjzGjkBEL1MIi7rWxsoOXl6KvX80IJ3SpnMomj5QXQ M5pVCEj59dgRk/U9o9FK+RgnG7tyHPha5FxPhPs0l15K/n0v6cnSXISJVpEddGFvtxXl tiFyY4t/CZ22VDiAeSTisA5tTewMd3GB/Npx7oBdUxLmWrs4lEiY+qWVDZFZQULnwdWS SJY9BfH2nZeNEAxtvxayRB6JUKIanPtxtRnNAslGJKYjyzvwBfut4J9UlITGPozU2PeM GR/kl2DR14WHMYeexbU8aDQRm2xy9aIijxqtsQ25EmXwIIwNkBa+OIoKr9u4ml/63GCA jJkQ== 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=B3AL0imNU7vsfvOuXqi+8Ne/yrl+L1bPANPnAD0U4Ac=; fh=gRV8c3odahPPYDAVIAwyTUz9l6OZEYAGdGe67uzT/fk=; b=KJebGHZJxlgv5ZTuHzIccjdlz+rHSJEe0SsDrg01cCJh42T+1gn0y22OIP1HZw0vzc 3YL37lRSs8Og7LJ8IJNxtdEw9wXSQ0E2BKZ248t1BtmF8t3CLUyHXLBNrhvMeqjwCYdd DxxTNac0kN5UUnPIJbB8h/B0s9+pDly4djTcwEP0CbP68RredxNk4+Ld8gPffQANOMnR haR+MYm9LCnnTgAz45Wde4DAeFP4zeUrzGpJSMH0590XI/ZV7j4STJ2rl/wbrv+myt6W yIXWYFj8sqcT8OTvh3xfYyH/fhLN3tA6kK6kt+jkBurR1vOqgc4N0MnoB+gFC/drzQYe Tyyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Hwp6d+Ej; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id v9-20020a056a00148900b006c0febe4496si9557479pfu.205.2023.12.13.04.09.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 04:09:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=Hwp6d+Ej; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id B5E7B80C0558; Wed, 13 Dec 2023 04:09:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233315AbjLMMI7 (ORCPT + 99 others); Wed, 13 Dec 2023 07:08:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231638AbjLMMI5 (ORCPT ); Wed, 13 Dec 2023 07:08:57 -0500 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CCFFCD; Wed, 13 Dec 2023 04:09:03 -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 2BC6666F; Wed, 13 Dec 2023 13:08:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1702469296; bh=jqhRjEL97tn66XG6waeuYNlSKAzpHyL1g4+7ALb8P6Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Hwp6d+EjAYB0geF68t4m6zgcSbUiP+a93h4cqFqIC3Vzcbm2w9XuqWaArOoceoFlp ISYe3zCw05UnSJi4G81SOMUr8xC/qfJqhBMNag4gvwnMMiO5gQbVLGBxIIIGSs537k HKFJpw8ki6RmYvuiLZW89YKvP8LMgmmqd1+lIOVc= Date: Wed, 13 Dec 2023 14:09:09 +0200 From: Laurent Pinchart To: Tomi Valkeinen Cc: Arnd Bergmann , Sakari Ailus , Mauro Carvalho Chehab , Nathan Chancellor , Jacopo Mondi , Hans Verkuil , Arnd Bergmann , Nick Desaulniers , Bill Wendling , Justin Stitt , Shuah Khan , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] [v2] media: i2c: mt9m114: use fsleep() in place of udelay() Message-ID: <20231213120909.GC769@pendragon.ideasonboard.com> References: <20231213112322.1655236-1-arnd@kernel.org> <5c5647d5-b389-4d71-9062-3a9921212079@ideasonboard.com> <20231213114812.GB769@pendragon.ideasonboard.com> <0722393c-8107-4a8f-b3ab-1bbb347a6f1b@ideasonboard.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <0722393c-8107-4a8f-b3ab-1bbb347a6f1b@ideasonboard.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Wed, 13 Dec 2023 04:09:08 -0800 (PST) On Wed, Dec 13, 2023 at 01:56:48PM +0200, Tomi Valkeinen wrote: > On 13/12/2023 13:48, Laurent Pinchart wrote: > > On Wed, Dec 13, 2023 at 01:40:54PM +0200, Tomi Valkeinen wrote: > >> On 13/12/2023 13:23, 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 > >>> > >>> In this configuration, the driver already fails to probe, before > >>> this function gets called, so it's enough to suppress the assertion. > >>> > >>> Do this by using fsleep(), which turns long delays into sleep() calls > >>> in place of the link failure. > >>> > >>> This is probably a good idea regardless to avoid overly long dynamic > >>> udelay() calls on a slow clock. > >>> > >>> Cc: Sakari Ailus > >>> Fixes: 24d756e914fc ("media: i2c: Add driver for onsemi MT9M114 camera sensor") > >>> Signed-off-by: Arnd Bergmann > >>> --- > >>> drivers/media/i2c/mt9m114.c | 2 +- > >>> 1 file changed, 1 insertion(+), 1 deletion(-) > >>> > >>> diff --git a/drivers/media/i2c/mt9m114.c b/drivers/media/i2c/mt9m114.c > >>> index 0a22f328981d..68adaecaf481 100644 > >>> --- a/drivers/media/i2c/mt9m114.c > >>> +++ b/drivers/media/i2c/mt9m114.c > >>> @@ -2116,7 +2116,7 @@ static int mt9m114_power_on(struct mt9m114 *sensor) > >>> duration = DIV_ROUND_UP(2 * 50 * 1000000, freq); > >>> > >>> gpiod_set_value(sensor->reset, 1); > >>> - udelay(duration); > >>> + fsleep(duration); > >>> gpiod_set_value(sensor->reset, 0); > >>> } else { > >>> /* > >> > >> I think this is fine, so: > >> > >> Reviewed-by: Tomi Valkeinen > >> > >> But: If we don't have COMMON_CLK (or rather, I think, HAVE_CLK), the > >> freq will be zero at compile time. So won't the compiler give a warning > >> for the DIV_ROUND_UP() call? > >> > >> Interestingly, for me, this doesn't give a div-by-zero warning: > >> > >> int x; > >> int y = 0; > >> x = DIV_ROUND_UP(10, y); > >> > >> but this does: > >> > >> int x; > >> const int y = 0; > >> x = DIV_ROUND_UP(10, y); > >> > >> And looks like this gives the warning too: > >> > >> int x; > >> const int y = 0; > >> if (y) > >> x = DIV_ROUND_UP(10, y); > >> > >> So, I think, the code in the driver could fail to compile at some later > >> point, if the compiler warnings are improved (?), or if someone adds a > >> 'const' in front of 'long freq = clk_get_rate(sensor->clk);' line. > >> > >> Maybe worry about that if it actually happens =). > > > > Maybe :-) I would be tempted to make VIDEO_CAMERA_SENSOR depend on > > COMMON_CLK. > > I think HAVE_CLK would be more correct. Indeed. Only arch/m68k (for Coldfire), arch/mips (for BCM63xx and Lantiq) and arch/sh (for pre-DT platforms) still make use of HAVE_LEGACY_CLK. It takes a long time to address the last users of a legacy API, but it seems we could get there one day. -- Regards, Laurent Pinchart