From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (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 EF5523BED47 for ; Thu, 5 Mar 2026 15:59:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772726359; cv=none; b=ZB+C0DzqEKVxsGZE+bpShznLFuTFIw3ugG4bvc7TRudn5IX5Az6hKtLgo22AjdtbTJ+/dJL9BWqbXyKczhqiEVNc56zZCxANdeHgovj9NlecmIQ+Tb9w+7rVpQGe6z7GsvIECMYnz2SsCB+8z8RuRm+6qARfZub4pB59xKRiybM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772726359; c=relaxed/simple; bh=nsz4kgvAEf+0wvPBtAtgWX1ce/NBoJxyIvXI/GBZp/I=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Q/ZM1e7WW6yZVuDHxgklR6OWCbHbuxwVlXQ1yG/b8JjHMx/7dzUauoJj6cBDjx+Q8KFzvSKAxuDWaB92iTQJ/R0+900Gd9Q5zwurnRzo/u8717zRIUO21XQBBPJvtD8M6BCOV/VBS/pFmyGv8uFQd3/TqbNULpktFvqcbemFHso= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=k726zjVG; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b=ceTl3w7l; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="k726zjVG"; dkim=pass (2048-bit key) header.d=oss.qualcomm.com header.i=@oss.qualcomm.com header.b="ceTl3w7l" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 625AULQL169350 for ; Thu, 5 Mar 2026 15:59:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= gJfVH6ArqBR8VxIevRdjDVBkwzQbm4lnsd8aP92U7Tg=; b=k726zjVGqsDbltY6 l3mDbNIktlyZSUcmAHUEUQ9uj9BxbnOjPARzrXKAuCz2a5Z3/sK1HRm8X/2ZGHwP f9qFwRA8hR0SLE7YPYEvDXd4vvaAM75wEB6SkgEhe8zvBjiUw/Y9MMJ0VmTf3fGK SPRQs4Bcyr6LD0EcG48CUlW1dYweV+9uOvcYLAq3bK24abFvULob5ylriq+tdbqT JrEoHHjZVU455RWI58rLBltSuH2/CAeM7Eo6VnKih1baStv01C/tk6XvYcCwcmXy 3zDCnF6kEOzm92tDwusjV06gjC520oc9YM6apvuvKdhnpT2KOusd/vFNv2PVDsgr pt2NkQ== Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4cq84w8yv3-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Thu, 05 Mar 2026 15:59:16 +0000 (GMT) Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-8cb4a241582so4288280485a.0 for ; Thu, 05 Mar 2026 07:59:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1772726356; x=1773331156; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=gJfVH6ArqBR8VxIevRdjDVBkwzQbm4lnsd8aP92U7Tg=; b=ceTl3w7lvUe5U5b3Kh6zob/PjuYpym6th8ctFsktrwwphl6MK9XtY7P56+gLYv8Og/ CZPITVhWGxTEOp5XJuIA5T+1gOxn0n7q6wsaNLhNoIszo/l562nkTPFVCUa0D8SGATGT opsdegMzEtXzXjqtL3+9ebnGKjy865pfbAWJuQlavlKa0XDxbuwSmWVNHXF1WN4d41PS izLcGwgqpOMT7tDto2aUZ3ve54ya3dOLEFlariGYWSfp2NGqMNhBWZSPc09S/hWjoTu3 7u5ELgotgmlbmwjm4VD1VOeljTbUCwg9yZfHE5wC70ytNNHkUib4uS2qLy2SrWFEfgzD iJUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772726356; x=1773331156; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gJfVH6ArqBR8VxIevRdjDVBkwzQbm4lnsd8aP92U7Tg=; b=OmiEE+QObDXmFFDeqkx9aY2oXe0AOJh982QNTSScLJwekJ+WdHpGHPzSKDL0pYPcpq LER1gt5OsmU6n/lpNNN0I4T16DkgpmGBtD4IBwYzkz4XZptq9XvjU2xeyNrm72gPKpGl HPKMp+Vh767lrP3su/WyVUT+NyS3Fc5TefE2QS+r0PaIPNoSRUBSIS55LWHAAquOU8eo CIdTVu2BR5BIlDusnR8BfTG+l2/RolbMPYu3g/BdH3WxPelk3Ftb10/a3iwJUxMLfW3O BtoGppEDQDaWcKYi9UV5j3nrAugY6zDWvEdxW00cT83exsbQH6fOjOS/aYKzWCvQMGDo /2VQ== X-Forwarded-Encrypted: i=1; AJvYcCXQ/qzcrXxw4iK1umGAaeBgE81d2pN337FJTpLWwRq1xTT4Nl7o1z2ZpYUYoQpIKw2P6o6BvN/nWPC3K08=@vger.kernel.org X-Gm-Message-State: AOJu0YwxsEynjn0IFULY2IIB9eb+DCSX8vfDQ/lExJYUxPD/WnF1DTU6 gFVJN5JYTInqjTRGvAD3tVVqO4mosdB6IRrmalAI9/xkZg4SD+i0LeTJwjwQLgBfXqLV3ZnNgPv TRw1tPupK5IFa2GJ1owpXwf+y+FR0ffwihwD5c4vLeDkyoXQq2hyBiCNYR0symwHCz9Q= X-Gm-Gg: ATEYQzwR7Ked6zo9OEdhrNjvaXblaL9J6l3JmzA0G4x+ivqwrToc2r2JCvRlAaDdxWZ TSHli/2+AjnTmBt8eLxtRufZnQl6Jk91UPlTS0IX5gSzjVVsPaNYZSyAg2zrazrPNSrxo/SoNlP FOK48o7WxVZQ75StgMpb7ozMebcYmHymX/s0USA0C8dT/hEIecH307DvAz3Az2SPvXv301RphDo M9IulW9MG3gEO5q+P5IxIwGkd9TiQwIuu3F4fSK9dshTwqcRO+pxu6bgiW1FY/XFK4Cxj6H6EuV WiGSs5Mpmrgo9RJ7nOr7m1oUb9wWHrLTUZGq3FLcz8KHG7/6D3rx4s7gJmsSK/huEYCcTIwJfFc N0Wrv/D2BfusjrX7Vaqf6IGxTrMpxNit8YepjYB8idZVoVUCZ X-Received: by 2002:a05:620a:4096:b0:8b2:74e5:b36 with SMTP id af79cd13be357-8cd5afa5ad6mr741187685a.68.1772726356002; Thu, 05 Mar 2026 07:59:16 -0800 (PST) X-Received: by 2002:a05:620a:4096:b0:8b2:74e5:b36 with SMTP id af79cd13be357-8cd5afa5ad6mr741182085a.68.1772726355454; Thu, 05 Mar 2026 07:59:15 -0800 (PST) Received: from [192.168.1.29] ([178.197.219.94]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4851fae00absm46179485e9.4.2026.03.05.07.59.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 05 Mar 2026 07:59:14 -0800 (PST) Message-ID: Date: Thu, 5 Mar 2026 16:59:12 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] ti: sci: Drop fake 'const' on handle pointer To: Andrew Davis , Nishanth Menon , Tero Kristo , Santosh Shilimkar , Michael Turquette , Stephen Boyd , Peter Ujfalusi , Vinod Koul , Frank Li , Thomas Gleixner , Ulf Hansson , Bjorn Andersson , Mathieu Poirier , Philipp Zabel , Dave Gerlach , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, dmaengine@vger.kernel.org, linux-pm@vger.kernel.org, linux-remoteproc@vger.kernel.org Cc: stable@vger.kernel.org References: <20260223202426.566958-2-krzysztof.kozlowski@oss.qualcomm.com> <195cc8dc-8642-481c-8bdd-f5409ab8f5b5@ti.com> <5b6a4284-4766-424c-9171-feaa08c52ad1@oss.qualcomm.com> <2d852f07-0bd9-4076-b0dd-93425ed237f4@ti.com> From: Krzysztof Kozlowski Content-Language: en-US Autocrypt: addr=krzysztof.kozlowski@oss.qualcomm.com; keydata= xsFNBFVDQq4BEAC6KeLOfFsAvFMBsrCrJ2bCalhPv5+KQF2PS2+iwZI8BpRZoV+Bd5kWvN79 cFgcqTTuNHjAvxtUG8pQgGTHAObYs6xeYJtjUH0ZX6ndJ33FJYf5V3yXqqjcZ30FgHzJCFUu JMp7PSyMPzpUXfU12yfcRYVEMQrmplNZssmYhiTeVicuOOypWugZKVLGNm0IweVCaZ/DJDIH gNbpvVwjcKYrx85m9cBVEBUGaQP6AT7qlVCkrf50v8bofSIyVa2xmubbAwwFA1oxoOusjPIE J3iadrwpFvsZjF5uHAKS+7wHLoW9hVzOnLbX6ajk5Hf8Pb1m+VH/E8b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1/u+33lBJgnAIH 5lSCjhP4VXiGq5ngCxGRuBq+0jNCKyAOC/vq2cS/dgdXwmf2aL8G7QVREX7mSl0x+CjWyrpF c1D/9NV/zIWBG1NR1fFb+oeOVhRGubYfiS62htUQjGLK7qbTmrd715kH9Noww1U5HH7WQzeP t/SvC0RhQXNjXKBB+lwwM+XulFigmMF1KybRm7MNoLBrGDa3yGpAkHMkJ7NM4iSMdSxYAr60 RtThnhKc2kLIzd8GqyBh0nGPIL+1ZVMBDXw1Eu0/Du0rWt1zAKXQYVAfBLCTmkOnPU0fjR7q VT41xdJ6KqQMNGQeV+0o9X91X6VBeK6Na3zt5y4eWkve65DRlk1aoeBmhAteioLZlXkqu0pZ v+PKIVf+zFKuh0At/TN/618e/QVlZPbMeNSp3S3ieMP9Q6y4gw5CfgiDRJ2K9g99m6Rvlx1q wom6QbU06ltbvJE2K9oKd9nPp1NrBfBdEhX8oOwdCLJXEq83vdtOEqE42RxfYta4P3by0BHp cwzYbmi/Et7T2+47PN9NZAOyb771QoVr8A== In-Reply-To: <2d852f07-0bd9-4076-b0dd-93425ed237f4@ti.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Proofpoint-ORIG-GUID: DHEx0SU0CXqYqt5YAFIZPNv16lkQxziu X-Proofpoint-GUID: DHEx0SU0CXqYqt5YAFIZPNv16lkQxziu X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMzA1MDEyOCBTYWx0ZWRfX5n9aYU291Y4+ B1dCQqa6CbhVbd5cuTBa586SVxyzZGu061ESokBOm2dhQFLpiwdvHBtzUgGfZbCO2HDJwLsaMcR CskSVIbMeGLuuAjV2zSv2sdhuPpceR/xftUXR77qBWs6JZJu50BYwXhHEl8qW8Ih2pSnSV03J9i U39MaTi0G84ccYbsOWaYRrqeCQuAlK36Jn5gwVi0iV7+lH4vvX7fFRVqXLyi+skgfh3NggcaJ5m O8fB9k/FxY+zdlAjXr6rG2kk4383hcqhWXeqBpVfXKyp1aPwL+iRS7N6z/CTxzJf5kgz4jmijN2 S/En00owOPErmU1uIUMy3BOhw5i1N61tnQwEZUU5DCtR2AURN30U895alBWo1UP8rBl6gRoT5pe fE4jovDXE2KZeZtxVG4kDrzr4WesAX5p/Zfs3jHbDbOehIABkOo9Omh83rKDQrHESTrbc+AtUsC NR4SL4x4MbveUnfR68A== X-Authority-Analysis: v=2.4 cv=N64k1m9B c=1 sm=1 tr=0 ts=69a9a854 cx=c_pps a=HLyN3IcIa5EE8TELMZ618Q==:117 a=gOEeR9iKwsj33Yj5oN/cWg==:17 a=IkcTkHD0fZMA:10 a=Yq5XynenixoA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=bHzazS_3SF2oTeVDu9QA:9 a=QEXdDO2ut3YA:10 a=bTQJ7kPSJx9SKPbeHEYW:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-03-05_04,2026-03-04_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 impostorscore=0 bulkscore=0 clxscore=1015 adultscore=0 suspectscore=0 spamscore=0 lowpriorityscore=0 phishscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2602130000 definitions=main-2603050128 On 05/03/2026 16:52, Andrew Davis wrote: >>>> The code is not correct logically, either, because functions like >>>> ti_sci_get_handle() and ti_sci_put_handle() are meant to modify the >>>> handle reference counting, thus they must modify the handle. >>> >>> The reference counting is handled outside of the ti_sci_handle struct, >>> the contents of the handle are never modified after it is created. >>> >>> The const is only added by functions return a handle to consumers. >>> We cannot return non-const to consumer drivers or then they would >>> be able to modify the content without a compiler warning, which would >>> be a real problem. >> >> This is the same argument as making pointer to const the pointer freed >> via kfree() (or free() in userspace). kfree() does not modify the >> contents of the pointer, right? The same as getting putting handle does >> not modify the handle... >> > > In that argument, if we wanted the consumer of the pointer to not free() > it we would return a const pointer, free()'ing that would result in the > warning we want (discards const qualifier). > > If you could somehow malloc() from a const area in memory then free() > doesn't modify the pointed to values, only the non-const record keeping > which would be stored outside of the const memory. So even in this analogy > there isn't a problem. I am not saying about malloc. I am saying about free() which does not modify the freed memory. > >> The point is that storing the reference counter outside of handle does >> not make the argument correct. Logically when you get a reference, you >> increase the counter, so it is not a pointer to const. And the code >> agrees, because you must drop the const. >> > > The record keeping memory is not const and can be modified. > > And where do we drop the const? The outer "struct ti_sci_info" was never > const to begin with, so no dropped const. We discuss about different points. I did not say the outer memory is const. I said that you drop the const - EXPLICITLY - from the pointer to handle. And that API which gets a handle (increases reference count) via pointer to const is completely illogical, because increasing refcnt is already modifying it. Just because you store the refcnt outside, does not change the fact that API is simply confusing. > > If the issue is that the handle is not const inside that outer struct > we could fix that, > > struct ti_sci_info { > ... > - struct ti_sci_handle handle; > + const struct ti_sci_handle handle; > ... > }; > > And with that change even your original commit message example issue > goes away, > > struct ti_sci_info *info = handle_to_ti_sci_info(handle); > info->handle.version.abi_major = 0; > > would now fail to work to compile. But you cannot do that for other reasons in your code because you DO modify the handle in all the APIs which you call "pointer to const". Best regards, Krzysztof