From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 CE1EB12CD8B for ; Thu, 15 Jan 2026 01:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768440630; cv=none; b=eUSyaGzbi75ODIbn2mpzFx/7AMC7OdyDqstKQmFc0STorUAxAaiU6YTEKZhtLAXhDVWGXq81sNi70mXXXI3iY0BHPH79nqUE4nsTaqUnz8JT30sphz1fr3MyN2VOiVctGucyZO61fND9V2BM3reYaK0rtT2sr+7gkJ4Iikpymh4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768440630; c=relaxed/simple; bh=xOBY9yy1BwvITSxKgaXO8hoGaEsJQxkIIOvURE5COUk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=o2pN5L/dwuAy8XSRPERThA2It6CA4klNyd2zgSlPkokskw+i8ETE0jm5xNCFTaPORfiHMJn8fzJ9tjeo5Zr+dqejg1g5FN+YE8vaYMDmeoF3HCjS3ORRGR0f77SuSLuxQPkRYEUivnOlft8X4CgK0Qb1BZ+e6yOC3LETlkL1Bsw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PSdP2q3X; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=pmoL+3Bp; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PSdP2q3X"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="pmoL+3Bp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768440625; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lHr8fzR9siY7kHK8auo6hhu8OpoWK5JbBKEhN8I4qKE=; b=PSdP2q3XNWSYB9hJy/sVoIeUh3Kxuoi1JkQGysYIPIm/TEY2dyWT6bI/uAQosoJzlbWVX+ NlV2KoFpThPDP//a8RRfeV3KqXqiTdEkW/NC0+gMlflkqCB5aXSZkq2rMI63pEO4GQ/I0K 6hWaASCS/KYo/qcP+J/4yjhh02tqNh0= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-277-ERLRwNTvMh-Gn41OzjReOA-1; Wed, 14 Jan 2026 20:30:24 -0500 X-MC-Unique: ERLRwNTvMh-Gn41OzjReOA-1 X-Mimecast-MFC-AGG-ID: ERLRwNTvMh-Gn41OzjReOA_1768440623 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-8c52fd4cca2so104389485a.3 for ; Wed, 14 Jan 2026 17:30:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1768440623; x=1769045423; darn=vger.kernel.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=lHr8fzR9siY7kHK8auo6hhu8OpoWK5JbBKEhN8I4qKE=; b=pmoL+3Bp2vJPeG0R4NPsypELgFC1ypojNPHmtu1EvnBLn1WT4lgjrJIZRHCZZsB7HV iWC+KMWs2RAQlz68sNH2UeLZg2YdgpJIQEWR4YUDoxmMppSjKye/Ql6LqMa2w9viq2Rq c60j+RNVpBw1EAjMiqrQ8Za+luuTairJhnLVAbkNYJcy3rLYmiW5FnvBLx1IdlRgoWFS HeTjkZbI8Ow+a+POeBgiiQ2TP+18664IPpyC5JtOcuyf51jD0mR3t72gx90TX+9/1cnm D+CFX3XCtd1BCd+SfCFjnA665Y5fcPJcCyefmPA8hPguV/9TApmDlVPE8vRAmn815j8i Toxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768440623; x=1769045423; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lHr8fzR9siY7kHK8auo6hhu8OpoWK5JbBKEhN8I4qKE=; b=ulZG9W2+Bzj8NXiqmnZM7MPGTfwW5GorS/ciFED8LlVBii+yZtI54sulpErxS96HIh zYJvuAgZ5OBAzBUDnUIbMpJaV+f70lbTW+GrUss1whKECWOVKEEWbvFpYGJm6vnaTHl9 f6u6XNWHI4V5/n2BaDXUHppXRnGlCvD37vd77YVyzM0lz2bZKaxnGt4KsWAfWVNPRUO4 DyvNIv/e7eUHj4TiF0CO7XPUKVRBjQfdcBWImnpx4XAljSyGGSQ+4InbtTLTRbV/SLLm R0ZqLqOvtL7LNoMZnh2d8YrmWILVOVBvL2sXJq1wc1oFYDuukj/jqNtUxEnJugKY8lri 5LkA== X-Forwarded-Encrypted: i=1; AJvYcCUW/7PfuxnyQvKS8bzeGxnAW5SMaSKNLX0hG6jlTDydj3zROkGrrlgkNYuvaVK8hjxwVxlTikchPA/9AbQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxKgMXuo3T6Y1lulFZBxcwHZs+c1RaPBdYJa2TuxdZol03cEbKA 0M7hpVCsPW/U+M0Hqg056no0kJfIB1GwpvK1E2WkYh/eAOG1vpChK68iNwC8noErex7dsqQ1JII gTtH+I/QZZ2znRaHdaJIhCABZfVQtCxR9VpHhBFqLqJIDE2Kk6nIxKqtBLBbhRlqfAA== X-Gm-Gg: AY/fxX4zA+od1Yufj5UNdDCWIgZC7QdYAaxbeSikeYBIRdYf/f7axB2jED6eCnmtXP7 BAUMg8kkF1usaxSb6Gh5esike+N7wNibqBw+NHw5NR2ll8FCEHGdHvUbeZie509vwtHamnzKFSU 7yhW/NbsJo9BgJyQa+6/BPET4jhCvvsVDKDHMUKNFo2KshvDhlYWcBHVMkXI+mNMTmwpO5lcQOP GFHde+rw5LJmIgcxTFv7rtRvEVCBEuQfbmnJOE6QobcJWhfELYTHCTDfX8AYgl+AfU569qRqL3q BfQH6znvZhq9dCs2RbgVNYOiPXFKIBmLawrX4b/0sPAEAK6GKYU71GexcIl9s8ogT+J/62TOXS8 sMcn9 X-Received: by 2002:a05:620a:4153:b0:892:43af:ba4b with SMTP id af79cd13be357-8c52fb3ab81mr706529285a.29.1768440623254; Wed, 14 Jan 2026 17:30:23 -0800 (PST) X-Received: by 2002:a05:620a:4153:b0:892:43af:ba4b with SMTP id af79cd13be357-8c52fb3ab81mr706526885a.29.1768440622864; Wed, 14 Jan 2026 17:30:22 -0800 (PST) Received: from redhat.com ([2600:382:851c:8241:679d:875:9f:9e57]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8c530b72649sm279629385a.34.2026.01.14.17.30.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jan 2026 17:30:22 -0800 (PST) Date: Wed, 14 Jan 2026 20:30:20 -0500 From: Brian Masney To: chuan.liu@amlogic.com Cc: Michael Turquette , Stephen Boyd , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] clk: Ensure correct consumer's rate boundaries Message-ID: References: <20260109-fix_error_setting_clk_rate_range-v1-1-bae0b40e870f@amlogic.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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260109-fix_error_setting_clk_rate_range-v1-1-bae0b40e870f@amlogic.com> User-Agent: Mutt/2.2.14 (2025-02-20) Hi Chuan, On Fri, Jan 09, 2026 at 11:24:22AM +0800, Chuan Liu via B4 Relay wrote: > From: Chuan Liu > > If we were to have two users of the same clock, doing something like: > > clk_set_rate_range(user1, 1000, 2000); > clk_set_rate_range(user2, 3000, 4000); > > Even when user2's call returns -EINVAL, the min_rate and max_rate of > user2 are still incorrectly updated. This causes subsequent calls by > user1 to fail when setting the clock rate, as clk_core_get_boundaries() > returns corrupted boundaries (min_rate = 3000, max_rate = 2000). > > To prevent this, clk_core_check_boundaries() now rollback to the old > boundaries when the check fails. > > Signed-off-by: Chuan Liu > --- > drivers/clk/clk.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > index 85d2f2481acf..0dfb16bf3f31 100644 > --- a/drivers/clk/clk.c > +++ b/drivers/clk/clk.c > @@ -2710,13 +2710,17 @@ static int clk_set_rate_range_nolock(struct clk *clk, > */ > rate = clamp(rate, min, max); > ret = clk_core_set_rate_nolock(clk->core, rate); > + > +out: > if (ret) { > - /* rollback the changes */ > + /* > + * Rollback the consumer’s old boundaries if check_boundaries or > + * set_rate fails. > + */ > clk->min_rate = old_min; > clk->max_rate = old_max; > } > > -out: > if (clk->exclusive_count) > clk_core_rate_protect(clk->core); This looks correct to me. Just a quick question though to possibly simplify this further. Currently clk_set_rate_range_nolock() has the following code: /* Save the current values in case we need to rollback the change */ old_min = clk->min_rate; old_max = clk->max_rate; clk->min_rate = min; clk->max_rate = max; if (!clk_core_check_boundaries(clk->core, min, max)) { ret = -EINVAL; goto out; } Since clk_core_check_boundaries() is a readonly operation, what do you think about moving clk_core_check_boundaries above the code that saves the previous values? That way we only need to rollback in the case where set_rate() fails. Brian