From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4868C433EF for ; Wed, 3 Nov 2021 02:26:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8480F610E8 for ; Wed, 3 Nov 2021 02:26:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231216AbhKCC3W (ORCPT ); Tue, 2 Nov 2021 22:29:22 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:27105 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbhKCC3U (ORCPT ); Tue, 2 Nov 2021 22:29:20 -0400 Received: from dggeme756-chm.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4HkVw64WdJz1DHkd; Wed, 3 Nov 2021 10:24:38 +0800 (CST) Received: from [10.67.110.136] (10.67.110.136) by dggeme756-chm.china.huawei.com (10.3.19.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.15; Wed, 3 Nov 2021 10:26:42 +0800 Subject: Re: [PATCH -V2] drm/sun4i: Grab reference of connector before return connector from sun4i_tcon_get_connector To: Maxime Ripard CC: , , , , , , , References: <33e01d45-c9f9-0e8c-6871-868ecd198368@huawei.com> <20211102084628.149070-1-heying24@huawei.com> <20211102150331.526nn2e6oqjbf6ur@gilmour> From: He Ying Message-ID: Date: Wed, 3 Nov 2021 10:26:42 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20211102150331.526nn2e6oqjbf6ur@gilmour> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.110.136] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggeme756-chm.china.huawei.com (10.3.19.102) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2021/11/2 23:03, Maxime Ripard 写道: > Hi, > > On Tue, Nov 02, 2021 at 04:46:28AM -0400, He Ying wrote: >> From the comments of drm_for_each_connector_iter(), we know >> that "connector is only valid within the list body, if you >> want to use connector after calling drm_connector_list_iter_end() >> then you need to grab your own reference first using >> drm_connector_get()". So fix the wrong use of connector >> according to the comments and then call drm_connector_put() >> after using connector finishes. >> >> Signed-off-by: He Ying >> --- >> >> V2: >> Use proper subject prefix >> >> drivers/gpu/drm/sun4i/sun4i_tcon.c | 18 +++++++++++++----- >> 1 file changed, 13 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/gpu/drm/sun4i/sun4i_tcon.c b/drivers/gpu/drm/sun4i/sun4i_tcon.c >> index 9f06dec0fc61..24fa6784ee5f 100644 >> --- a/drivers/gpu/drm/sun4i/sun4i_tcon.c >> +++ b/drivers/gpu/drm/sun4i/sun4i_tcon.c >> @@ -47,12 +47,12 @@ static struct drm_connector *sun4i_tcon_get_connector(const struct drm_encoder * >> drm_connector_list_iter_begin(encoder->dev, &iter); >> drm_for_each_connector_iter(connector, &iter) >> if (connector->encoder == encoder) { >> - drm_connector_list_iter_end(&iter); >> - return connector; >> + drm_connector_get(connector); >> + break; >> } >> drm_connector_list_iter_end(&iter); >> >> - return NULL; >> + return connector; > Connector might be uninitialized if we don't find one here Connector should be NULL if we don't find one. The code is #define drm_for_each_connector_iter(connector, iter) \    while ((connector = drm_connector_list_iter_next(iter))) So, when we don't break from the while body, connector can only be NULL. > >> } >> >> static int sun4i_tcon_get_pixel_depth(const struct drm_encoder *encoder) >> @@ -65,6 +65,7 @@ static int sun4i_tcon_get_pixel_depth(const struct drm_encoder *encoder) >> return -EINVAL; >> >> info = &connector->display_info; >> + drm_connector_put(connector); >> if (info->num_bus_formats != 1) > We're still accessing connector->display_info here, but it might have been > freed already. Agree. I'll place it after using 'info' finishes in v3. > > Maxime