Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2414994rdb; Mon, 5 Feb 2024 06:05:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IElBAqjt7o3FmRcNsWRZNDFElGI2S3wfXgUlI4aESPQau0vFPR5NE9my8jy5oevB/pD7h3r X-Received: by 2002:a17:906:22d3:b0:a27:6570:adbc with SMTP id q19-20020a17090622d300b00a276570adbcmr6147569eja.33.1707141940969; Mon, 05 Feb 2024 06:05:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707141940; cv=pass; d=google.com; s=arc-20160816; b=JODWCfXxWZtSVkZEU+HsR1g+UfsU4QOYNUb3h9+F621KvtZpN53JMZG1Owo5KxC8mU zwp8sNI7ToEMLkbnR1H6wgE7ra6QQslylDU7KNpf9VnA+3XJUVH58qJYBD5kn3XdqtgD QY0apB6kTvTz/YFMjgzjIt6S3c5Dw9A4jMjACBarPzkNP3n7+Qhs83AasocbeobxZwLn NjFqYF9ZQQIySa2XlvJU9Ss23Rwus0h28vh8jmwWJwPL54y1CXSnVo9tWY/VsrRmvf3q DuiAZo13lHKfOZr8bqtI166DFNZIRtbFCR5repFi8IJn42TiQrJ+hxrJ1f02rVSkePZe WYQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=tWHCZPGdnVP9n6u5fBWigVBsLLeSsPy8VL0rQblycqY=; fh=B9nFzbotwVb0TwFTRoxrtr0iU81O8Rs4cCN3OtGavjI=; b=RLyFWHiqfHtelmc0v7FpHhrPzE69UL8Ev2EnLa4FVmAij6kCe2wa7C7CEXjgEVZD2J eMH9eMV7uNg6nS0TX7dP1lVOljphSI43hZO3C/KA6DKdnbfR8mmBzD091S+SJj4aIJgm fe+WG4zfy62KLBZ+VpiOr6pca+DrfqhtqNtg2w1F8SzwwDkBsawUxbArFdfEC8dms+Ou en1RGzzbA0vCe8pFYVPlTbgtcgQ6T5KxioYJI/FOJZSQJD4ueaRGJ8mcZod0ftWrVOfB ViRfIJMDHVLqiJr5qMX5Lidp0Fa6kzs42VGEy0qQD4egJqgWiH8UtA7cK9fNOlDzJglo uRVA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="mOezREo/"; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-52779-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52779-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com X-Forwarded-Encrypted: i=1; AJvYcCUk3faebmECSONwSkOX6ALypuqMIqPNUXkU14CTvQCSwTscFPcVkHQMWwQ3OBSNBSe8U81n3AJUgnqpRD4LD1mtiBVN4EXmGoQDhTrdFg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q17-20020a1709063d5100b00a37905c1452si1728963ejf.678.2024.02.05.06.05.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 06:05:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52779-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="mOezREo/"; arc=pass (i=1 spf=pass spfdomain=ti.com dkim=pass dkdomain=ti.com dmarc=pass fromdomain=ti.com); spf=pass (google.com: domain of linux-kernel+bounces-52779-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52779-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B4E9B1F23008 for ; Mon, 5 Feb 2024 14:05:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 276C12C190; Mon, 5 Feb 2024 14:05:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="mOezREo/" Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43A1F23768; Mon, 5 Feb 2024 14:05:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.19.141 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707141914; cv=none; b=l5b2nc/Eow22bsSHVatH3vHDFoObjktWJFgcDrj0RrCS+c7iAVlZrCltyu3+9p+sK56j1Jq1nXlf1K2QEoqHlxWA6Y/6G0CWIs3pCjbFhqlB3zmyASkzP3gwm2/FTm7/Fo5r4HaK62/CG9wW907l+jhZEnBZba3/gu6iS8AxGfc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707141914; c=relaxed/simple; bh=4bIEfg7PdUaON+zlchHH8C9f6qqA8dXeOfMbDZuxrhw=; h=Date:From:To:CC:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=rOdsxYSAFPFDKXvWxpO1Xu39IebRqulv7Ghriua0/R95bDm/93/Vv6xLvJUDRf5zX2WVsoJ2i4134AmTNf6Dxo1NVbT0+TUmhSBK6/wXmL6D03nZxUCggtAu2at0lsrZxlDECSGUW3swboT9xdCqBNPTzd1jiqcxC4liK1fdqMk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=mOezREo/; arc=none smtp.client-ip=198.47.19.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 415E50ig023002; Mon, 5 Feb 2024 08:05:00 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1707141900; bh=tWHCZPGdnVP9n6u5fBWigVBsLLeSsPy8VL0rQblycqY=; h=Date:From:To:CC:Subject:References:In-Reply-To; b=mOezREo/iNM/aeAbvC6SOz5GAuInx3j8MW55bLKM71fM4VJ8t7Nk0HvsZgKAxwML/ Wc+xXyOGBSXbDMZxmE92/1uDO0X9fWFd2dAkEGhGc5H0GgBfAJ0Lx68tWz0/OwGrIa AwQub8cyiH8ru32LKiG/oFJ6RnenEzWRQU1lRTNE= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 415E50SH032340 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 5 Feb 2024 08:05:00 -0600 Received: from DFLE103.ent.ti.com (10.64.6.24) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23; Mon, 5 Feb 2024 08:04:59 -0600 Received: from lelvsmtp6.itg.ti.com (10.180.75.249) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.23 via Frontend Transport; Mon, 5 Feb 2024 08:04:59 -0600 Received: from localhost (uda0133052.dhcp.ti.com [128.247.81.232]) by lelvsmtp6.itg.ti.com (8.15.2/8.15.2) with ESMTP id 415E4xjt050034; Mon, 5 Feb 2024 08:04:59 -0600 Date: Mon, 5 Feb 2024 08:04:59 -0600 From: Nishanth Menon To: Udit Kumar CC: , , , , , , , Subject: Re: [PATCH v1] clk: keystone: sci-clk: Adding support for non contiguous clocks Message-ID: <20240205140459.orjvjqqtiugmyosc@obscurity> References: <20240205044557.3340848-1-u-kumar1@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20240205044557.3340848-1-u-kumar1@ti.com> X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 On 10:15-20240205, Udit Kumar wrote: > Most of clocks and their parents are defined in contiguous range, > But in few cases, there is gap in clock numbers[0]. > > Driver assumes clocks to be in contiguous range, and assigns > accordingly. > > New firmware started returning error in case of > non-available clock id. Therefore drivers throws error while > re-calculate and other functions. What changed here? started returning error for what API? also please fix up 70 char alignment -> there extra spaces in your commit message. > > In this fix, before assigning and adding clock in list, > driver checks if given clock is valid or not. > > Fixes: 3c13933c6033 ("clk: keystone: sci-clk: add support for dynamically probing clocks") > > [0] https://software-dl.ti.com/tisci/esd/latest/5_soc_doc/j7200/clocks.html > Section Clocks for NAVSS0_CPTS_0 Device, > clock id 12-15 and 18-19 not present > > Signed-off-by: Udit Kumar > --- > Original logs > https://gist.github.com/uditkumarti/de4b36b21247fb36725ad909ce4812f6#file-original-logs > Line 2630 for error > > Logs with fix > https://gist.github.com/uditkumarti/de4b36b21247fb36725ad909ce4812f6#file-with-fix > Line 2594 > > drivers/clk/keystone/sci-clk.c | 20 ++++++++++++++++---- > 1 file changed, 16 insertions(+), 4 deletions(-) > > diff --git a/drivers/clk/keystone/sci-clk.c b/drivers/clk/keystone/sci-clk.c > index 35fe197dd303..d417ec018d82 100644 > --- a/drivers/clk/keystone/sci-clk.c > +++ b/drivers/clk/keystone/sci-clk.c > @@ -517,6 +517,8 @@ static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider) > int num_clks = 0; > int num_parents; > int clk_id; > + int max_clk_id; > + u64 freq; > const char * const clk_names[] = { > "clocks", "assigned-clocks", "assigned-clock-parents", NULL > }; > @@ -584,6 +586,7 @@ static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider) > } > > clk_id = args.args[1] + 1; > + max_clk_id = clk_id + num_parents; > > while (num_parents--) { > sci_clk = devm_kzalloc(dev, > @@ -592,11 +595,20 @@ static int ti_sci_scan_clocks_from_dt(struct sci_clk_provider *provider) > if (!sci_clk) > return -ENOMEM; > sci_clk->dev_id = args.args[0]; > - sci_clk->clk_id = clk_id++; > - sci_clk->provider = provider; > - list_add_tail(&sci_clk->node, &clks); > + /* check if given clock id is valid by calling get_freq */ > + /* loop over max possible ids */ > + do { > + sci_clk->clk_id = clk_id++; > > - num_clks++; > + ret = provider->ops->get_freq(provider->sci, > + sci_clk->dev_id, sci_clk->clk_id, &freq); > + } while (ret != 0 && clk_id < max_clk_id); take clock ids 0 1 2 3 -> Say 2 is reserved. num_parents = 4 while(num_parents) Loop 1 -> clk ID 0 is valid, list_add_tail while(num_parents) Loop 2 -> clk ID 1 is valid, list_add_tail while(num_parents) Loop 3 -> clk ID 2 is invalid.. so we scan forward to clk ID 3 -> list_add_tail while(num_parents) Loop 4 -> clk ID 4 is invalid.. but 5 is out of range, so we break off loop. sci_clk is still devm_kzalloced -> but since clk_id > max_clk_id, we jump off loop, and we dont add it to tail. so one extra allocation? If we have multiple reserved intermediate ones, then we'd have as many allocations that aren't linked? Could we not improve the logic a bit to allocate just what is necessary? > + > + sci_clk->provider = provider; > + if (ret == 0) { > + list_add_tail(&sci_clk->node, &clks); > + num_clks++; > + } > } > } > > -- > 2.34.1 > -- Regards, Nishanth Menon Key (0xDDB5849D1736249D) / Fingerprint: F8A2 8693 54EB 8232 17A3 1A34 DDB5 849D 1736 249D