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 323E1378814 for ; Mon, 27 Jul 2026 15:58:18 +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=1785167900; cv=none; b=R1fIrNJ9x09JDgT5wNhkIszxb9aV8Y/JxK8tYHWNvfvbASYpR2Pwndbz1i8sogCA7nMZ0SukyP+ZJUfU/sZg/oBFiDPJRsyKN8a9yCeg2PkqR+cWKGrcasu7KTysESQZIKjo9EOgEMQ3+8G6ZNBJ3fmxn29f6KphChgPxlAY+eQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785167900; c=relaxed/simple; bh=iCiarSCuW3q4ChQRODnHqSxkIANQKGTG92VF4M6+0so=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jrfg/vB+nZn7yznCTUpiWnUa5cQRBQJ8Uwa1ktoROG4NHSFV8p5HBWZ8ZHIJcGSP9V0iYHPDK3O0JlhhwiLuVXlmaUrIrob3DVMFY/KsSSbsdS8lVYkK3IMd3c0cyXOGj4Lp5V8BFFTRiN2sFpmCO+Hw4ZgCNv/HMHYb9k37IMg= 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=NgTJald8; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=C3VNtS3o; 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="NgTJald8"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="C3VNtS3o" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785167898; 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: in-reply-to:in-reply-to:references:references; bh=mFdWPVxbPSNgdFlp1FXPzOluFs4XWj1Cw/g1oEMc7zs=; b=NgTJald8r+ZmbjwtQW5uxGNj2RSLVeG083vI1y+DBJYBrXCg2IFtGmK9biywpupTS2SNBJ /RRgQRShT71IZCZoIUXfMlZVp7nhbXyKw3opD22YA7bD92vhJARFClcEnM9bXevaOXDBUp /FLahjCm6aXfWHydzaDC4QyXhkgsqb0= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-411-3aVSshaFMzGjiEF4P0K71w-1; Mon, 27 Jul 2026 11:58:16 -0400 X-MC-Unique: 3aVSshaFMzGjiEF4P0K71w-1 X-Mimecast-MFC-AGG-ID: 3aVSshaFMzGjiEF4P0K71w_1785167896 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-92e820609d9so282294685a.2 for ; Mon, 27 Jul 2026 08:58:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1785167896; x=1785772696; darn=vger.kernel.org; h=user-agent:in-reply-to:content-disposition:content-type :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to:content-type; bh=mFdWPVxbPSNgdFlp1FXPzOluFs4XWj1Cw/g1oEMc7zs=; b=C3VNtS3orUwBTYCsoUslPneY0h0Sb0r9WmAxGpUBF8tvT+FocOy26QJV7jl8a0I18z fWG3vDcc3pfOSyTDm8vNGbvwU+u3WHD9My/uLFRF3lpJ4Pjyl5WbyvCqmjJBC29We978 9R9mNbGcSp5335WvOfXsPDrNlfDVPEKvup94mRiimNcA9JoTPRSAl1D+sx6e22zcFE98 +P4gQLzvaIL89Fccx8BXKht7YgN0aeFOx4x5NgRlk0qSG5GBN7cP3YiKZJ2Zaz4eKvl2 1qcXHFJHpyBW1/qNNOdW/XxD5QrQkpGxAa7MrfL0COHLGL6MluNiRmVGtTQbQJyzxoBC Q2jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785167896; x=1785772696; h=user-agent:in-reply-to:content-disposition:content-type :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 :content-type; bh=mFdWPVxbPSNgdFlp1FXPzOluFs4XWj1Cw/g1oEMc7zs=; b=ePsvATA/SebOhF1L1+tfF/lhZaGa2kzLJ3dhdZUtX61uV2xCbZdsbDF5wZXog8AGeB rVvyr6foE+1l+lQXX7icegVCGlxj4dfKCYVEGwSb5g06fMY2n4on/iorrv8vRSfRW2wm jlZGff9DYY11TNhbo2zEJ+Wkj5cGcmwjE1U8fn48v37ZYS8k2tc6o0ve727gTo0vVTAt viM8EDTKQZcKDkAWGyFBaS2+TMhbjlI2eeOwE2ud2JE6xW3WPiCVd2Jw4lU//GRV55Pn QA0N7hIWhj0sH+uIpf2T/A/jaGHSp0fcDGARPDKoBfMqCBSXohEfJvjlEbRTd6cirY7B 376g== X-Forwarded-Encrypted: i=1; AHgh+RqoKHNsDp4zCfUA5fHX0338uDSm36nxVL55xO4K9f8xG72XHMoaNVZ+FlF/SjOeshvLUvT/WEwYNTa5ef8=@vger.kernel.org X-Gm-Message-State: AOJu0YxIkRMYaWn5UvwkphFNZriYcN5js05uA8SWLOKqGZSx34KFkjBL gvwiLrS5CnGc4kjsXOTbYLIW2C++kik3id/R1pVOYXRoYw1BnQqp8Mrj0WSv15OuOeuG5lEnWNL utzciyAYlRgqNoowVDSHLlqfZW9xWiG84dyNwg4SuMDBRKHoJ1ccTRsCbuek7uzp6yQ== X-Gm-Gg: AR+sD112pGbS7kSKzWFnyXCAvoAh866ObPEKSGL7gP9nwJ2+wAXvEJPKVYAK6Tlwaq1 aeRq7QqMAsmXMDD2VDbFr275fXqiCGCO70t06qhxeW8bIa5c81/ubhYT0Xaf0NvXQXlf4FTkd4U DYj7Erwbjijk4tFfv0GzL7UWCAWPFpTDDWa+FtW7zeUspO45YjJHc8GPs/eB7wr2nhXe5ixT7Fg tx9vKVtlwLDlV7r6w0qqRDg/lyDtnfxv/Preg97K9Y3X2/Qy2nZUr2aoM/V/ZBj0DMOcptNU/DF cWKkOJljJzXJ2wLLQMNzAO67eJXOPMPyIh0Z/e2YC4qAQxyR0csV9W6qGc7BiQsy6EGUvJi04ZY 3RxBEUvHQxYU4hD33MWCg4E+55anvnKXHcYo= X-Received: by 2002:a05:620a:298a:b0:915:fb92:d599 with SMTP id af79cd13be357-932df5d9720mr938360885a.25.1785167895877; Mon, 27 Jul 2026 08:58:15 -0700 (PDT) X-Received: by 2002:a05:620a:298a:b0:915:fb92:d599 with SMTP id af79cd13be357-932df5d9720mr938356685a.25.1785167895425; Mon, 27 Jul 2026 08:58:15 -0700 (PDT) Received: from redhat.com (c-73-183-53-213.hsd1.pa.comcast.net. [73.183.53.213]) by smtp.gmail.com with ESMTPSA id af79cd13be357-932de519154sm656292785a.5.2026.07.27.08.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2026 08:58:14 -0700 (PDT) Date: Mon, 27 Jul 2026 11:58:12 -0400 From: Brian Masney To: Praveen Talari Cc: bjorn.andersson@oss.qualcomm.com, Michael Turquette , Stephen Boyd , konrad.dybcio@oss.qualcomm.com, mukesh.savaliya@oss.qualcomm.com, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, chandana.chiluveru@oss.qualcomm.com, Sebastian Reichel Subject: Re: [PATCH v2] opp: Use clk_get_optional() to avoid leaving opp_table->clk as an error pointer Message-ID: References: <20260725-fix_ptr_check_on_clk-v2-1-7f269f7d33f3@oss.qualcomm.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: <20260725-fix_ptr_check_on_clk-v2-1-7f269f7d33f3@oss.qualcomm.com> User-Agent: Mutt/2.4.0 (2026-06-19) On Sat, Jul 25, 2026 at 11:58:22PM +0530, Praveen Talari wrote: > _update_opp_table_clk() uses clk_get(dev, NULL) to acquire the > device's clock. On platforms where the perf domain device has no > Linux clock and is instead managed entirely by firmware via > devm_pm_opp_of_add_table() (through > of_genpd_add_provider_simple()/onecell()), clk_get() returns > -ENOENT. That case is treated as valid (the OPP table can still > have entries sourced from firmware), but opp_table->clk is left > holding ERR_PTR(-ENOENT) rather than being reset to NULL: > > opp_table->clk = clk_get(dev, NULL); > ret = PTR_ERR_OR_ZERO(opp_table->clk); > ... > if (ret == -ENOENT) { > opp_table->clk_count = 1; > return opp_table; /* opp_table->clk is still ERR_PTR(-ENOENT) */ > } > > Consumers that only check IS_ERR(opp_table->clk) treat this as a > valid clk and pass it straight into the clk consumer API. In > particular, dev_pm_opp_set_rate() calls > clk_round_rate(opp_table->clk, target_freq), and clk_round_rate() > only guards against a NULL clk, so it dereferences the error pointer > to read clk->exclusive_count and crashes: > > Unable to handle kernel NULL pointer dereference at virtual > address 000000000000002e > ... > pc : clk_round_rate+0x3c/0x188 > ... > Call trace: > clk_round_rate+0x3c/0x188 (P) > dev_pm_opp_set_rate+0x114/0x33c > > Rather than teaching every clk consumer API to special-case > ERR_PTR(-ENOENT), fix it at the source: use clk_get_optional() > instead of clk_get() in _update_opp_table_clk(), which already > translates -ENOENT into a NULL clk. This documents that the clock is > genuinely optional for such devices, and keeps opp_table->clk holding > either a valid clk or NULL, never a lingering -ENOENT error pointer. > _opp_config_clk_single() is only wired up via opp_table->config_clks > when a clk was actually found, and every other opp_table->clk > consumer already tolerates NULL through the standard clk API (which > treats a NULL clk as a no-op), so no other call site needs to change. > > Suggested-by: Sebastian Reichel > Signed-off-by: Praveen Talari Reviewed-by: Brian Masney