From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74EA637CD30 for ; Thu, 21 May 2026 09:49:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779356965; cv=none; b=EY7kiONQRlvI3TL0/p4T/XletnTDoBEcMH7+SnNVDX9jB/1R+rW0LaMoPGvNWR8llVkHyX2CYm6xnS27m+zpmZtDq12SEVUv+3BOGBRLg8bC6hIYZJjQumTAQojKN4iOkuQbv0SOl72ChbzQYAv5zl8AOPEV9FTcy/26rasHDxI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779356965; c=relaxed/simple; bh=N6EO4CJVR+RpYRaHJ7cUZYVGH3Td95ZgNnjW+oNEKPY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PF/Gfspt6yv3PBDJS3DJNGszMSulGWg0OWFsMqU3lIBKLB6Ieec514mmA5Zs2Su4SxEEnQGO9Qo9U/K+HPtu/XJ1z1reaEEzF/xop9OYDhHG9SslXhpYJVbo15eOdiVLhi1kKbWETodokaqnBVNKAEitvJUFuJse4QRy5d/Bjxw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch; spf=none smtp.mailfrom=ffwll.ch; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b=P0s7Sce0; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ffwll.ch Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="P0s7Sce0" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-48984d29fe3so64438585e9.0 for ; Thu, 21 May 2026 02:49:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1779356962; x=1779961762; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=ReaflicG9jxrT121Yp+YbEeNKaO7PwpYEUsDZm4g/qo=; b=P0s7Sce0SInxRFbv3WnHVcdq51SZDjDylN0fOc0vynRgZ9b5TCzU0sp6okplcq/YWw lclxMhC2lY1ZoIn1mpX+qEwSNxHWQj5IEQxfPOFxG19+m9L8PmxF8VgNNOTGsnb2y748 ljxw3UgRByr01y6fhIgtNrKtHPvqUz/JtTpQc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779356962; x=1779961762; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ReaflicG9jxrT121Yp+YbEeNKaO7PwpYEUsDZm4g/qo=; b=Ykzg1WaesflDCXrAYJ/rnFWdIOxPscvdnJ4QkCrTWbldWuVRn/SsOdK7ZgKvQGaC35 mF0thUXHzoYff/jrXhumpOIIewgx86z6j6iWPnbB+9e5shmFmsxHqY9yluqVbNWxpNeN LTk+tGKpGWtocZoIlmryrS6mGF4UsLrcMe6H7ZlRBHOovKAhzmv54bselsqG4bIv9UKH eNJiAvtB/4zofanxj/btdV17ouqydAVMNlAcNlGdxxey6MHoQouCd17IdsDcsJhjJglQ 5QEfysBuxPJ8EdvhY/6NmdIAATuXJFR4r5LjUhRYOvF6HfNoteyk8Dnw4YJ6US5KFT5f DW1g== X-Forwarded-Encrypted: i=1; AFNElJ8R/7RIZGHGIpbDedPaInhQyAiDG0Fg86q5HPxjm71332eK00f01PshtJPoOxVCefMycLWxNJa3KNvpwg4=@vger.kernel.org X-Gm-Message-State: AOJu0YwWM2B/oJlN/kcYweOLD8HUsTKfje2KL+6WnH0ACgtvBCu6AwTq QlytmJ2XUi97qtbMMNdPGHCERR4HDUoXqsiUqgdXq+ugTUq/Ud1+HrIMg8ciukdFJ1E= X-Gm-Gg: Acq92OHhkAy3aYnSO7/8ZsQwzxa71WjROZKFeCtAhD3UjThKj7TUt/S0BxjC86vvN6H ZcJLN5D7lsrafNkc9yuwYJ6uBYERfssv1f3I3CRt24zX1DEpn4ALFvtosxez7NXzWeZ2OCbTy9m BwiOapaJHAIuHpQtvGtZIFbso6+W+i2kvyiJCl+KZjt8mKgEOy1F4gUzTZn+Htz7nDptCzsndmN 8MuRdxKotyMFzzuGD4VCiAxRERE2TnIqx3dQ4hTF3i0aQMlvrECg8LiBKQzIkhZaMx37eRPrZNp 4870ZrhIJmLDrOVfZHJ5o0rHxmJz7biM5uQ23a0k5MEIcI9X/NGGvcBsvp8ggnexDSonIEzybON eLACW2nnCbLNAx979rtRC9TB+8KU6FMF3jQq2hENvU4b+EOyi4RtfS5UO3UzE3HVZ5t59uA20yx US49H4cBlrmI95JkRPHt21FBQkqrjePAbUbWbRD2gXsK4wug== X-Received: by 2002:a05:600c:4fc7:b0:48a:66a8:9981 with SMTP id 5b1f17b1804b1-490360ddce0mr26992815e9.27.1779356961554; Thu, 21 May 2026 02:49:21 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:5485:d4b2:c087:b497]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4903c9a5108sm14370715e9.6.2026.05.21.02.49.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2026 02:49:20 -0700 (PDT) Date: Thu, 21 May 2026 11:49:18 +0200 From: Simona Vetter To: Maxime Ripard Cc: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Jyri Sarha , Tomi Valkeinen , Devarsh Thakkar , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 02/28] drm/atomic_helper: Skip over NULL private_obj pointers Message-ID: Mail-Followup-To: Maxime Ripard , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Simona Vetter , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Jyri Sarha , Tomi Valkeinen , Devarsh Thakkar , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <20260423-drm-state-readout-v2-0-8549f87cb978@kernel.org> <20260423-drm-state-readout-v2-2-8549f87cb978@kernel.org> 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: <20260423-drm-state-readout-v2-2-8549f87cb978@kernel.org> X-Operating-System: Linux phenom 6.19.10+deb14-amd64 On Thu, Apr 23, 2026 at 12:18:15PM +0200, Maxime Ripard wrote: > Just like for connectors, drm_atomic_state contains an array of Maybe s/connectors/all other objects/ because for a moment I've pondered whether we do this because connectors are special as dynamically created/refcounted kms objects. Unlike planes/crtcs and private objects. With that also Reviewed-by: Simona Vetter Cheers, Sima > drm_private_state, with the number of states found in num_private_objs. > > If we are to clean up a state by hand for some reason before calling > drm_atomic_state_put(), chances are that the pointer to the affected > drm_private_obj and drm_private_states would have been cleared to avoid > any use-after-free. > > However, since it's just an array, as we progress and free the items, we > can't update num_private_objs as we go since we would reduce the array > size, preventing us to remove the final elements. > > And if the caller was to forget to update num_private_objs after it > iterated over the whole array, we're left with a (valid) array with a > non-zero number of NULL elements. > > If we were to call drm_atomic_state_put() at this point, chances are > that drm_atomic_state_default_clear() would be called and it would > iterate over all those empty NULL items. > > However, unlike what is found for connectors, crtcs and planes, we don't > test that our pointers are non-NULL before dereferencing them, leading > to a NULL pointer dereference. > > Such callers should obviously be fixed, but there's no reason to not do > such a simple check, if only to be consistent. > > Reviewed-by: Thomas Zimmermann > Signed-off-by: Maxime Ripard > --- > drivers/gpu/drm/drm_atomic.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c > index 3bd52602fe30..84bc91886b4c 100644 > --- a/drivers/gpu/drm/drm_atomic.c > +++ b/drivers/gpu/drm/drm_atomic.c > @@ -334,10 +334,13 @@ void drm_atomic_state_default_clear(struct drm_atomic_state *state) > } > > for (i = 0; i < state->num_private_objs; i++) { > struct drm_private_obj *obj = state->private_objs[i].ptr; > > + if (!obj) > + continue; > + > obj->funcs->atomic_destroy_state(obj, > state->private_objs[i].state_to_destroy); > state->private_objs[i].ptr = NULL; > state->private_objs[i].state_to_destroy = NULL; > state->private_objs[i].old_state = NULL; > > -- > 2.53.0 > -- Simona Vetter Software Engineer http://blog.ffwll.ch