Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp2105511rwl; Fri, 6 Jan 2023 01:51:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXulbherT7EbJetiQ5jb38lPr9dsn83huF6kaiGqWWzyG0CiFfum2O6/fRwnk76PC630GC+k X-Received: by 2002:a17:907:7707:b0:844:c651:ce4b with SMTP id kw7-20020a170907770700b00844c651ce4bmr45272660ejc.33.1672998699790; Fri, 06 Jan 2023 01:51:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672998699; cv=none; d=google.com; s=arc-20160816; b=i+idPJ3S4NUfpkfajwHNJio5Lwx97OnfFpgnHIhgSOG+peZMV/AHBwsxJ3459qUSSO IvkkzTIjySS0oItJswoAr5MUVlW0c1AeV3eHt2ggQ4c1xKcIXVxwximadrliTl0lgXT1 ZtBbQWhR5+95YdISdwTf2dBXQN9gaf35iocggBG6m/laQ820l05DLQJZshJ5WFvtzi5y Q+LR0LPaY6d9thuHrK2fhtrjWMSuW6sruuI74BDWVbUBgn7jMeK54qZyBJTUbAhR+nhY V3H3nJa3hBWpdJVVPJNJe+hXUijAunyu+FGqRp87KpRFI5KTZ2l7kF46pqQISDApXBH+ lWLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Me/kk+3Tyr8dmVSsoyIF+O2KsldtdioDapYVcjtoh5o=; b=0ntcuuwbWmDsCaPghj899v1LtgzB5YUHSfQZOsiWRViBN3yG8vN8WX1rk8z1xNroNe k1+trOWmHeMM2G77eM8k8eJWIlifThVgVAjELZMiX9W9QBmbQvPtugqyZxGJ9rq7yWHU InhqE9q6U4ICMxhPGssObvFBurZf6ymcUYZzTnSu3ZxTHgJnHx478ZepnMb19+fs0zb6 brjehE/OA73Os9ek2BJ0pA6UC9XO5iPYi7HttQ2+btBa48o/YsFZ4MOPVRN8d+rGay94 MMA9HZ+uXuxTQOKh8JO0XPougiZUEzbhq3qdlH04bYn/l0s7H5wq0MVdHQk/K/f7DCbT KBnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eHiyA4p0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs18-20020a170906f19200b0084c6438e6bdsi591726ejb.805.2023.01.06.01.51.26; Fri, 06 Jan 2023 01:51:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=eHiyA4p0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233219AbjAFJj3 (ORCPT + 56 others); Fri, 6 Jan 2023 04:39:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232990AbjAFJjI (ORCPT ); Fri, 6 Jan 2023 04:39:08 -0500 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9738243E58 for ; Fri, 6 Jan 2023 01:30:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672997414; x=1704533414; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=L3XLTnt2PC2phaQBntNILIbKLlk/h/c2gjDwb/kJpOc=; b=eHiyA4p0oVsM9/VudTH8EKBd6MXJxLPJdkuz4aUpDsWtMqJ3zrpbNxGO vWkWix9FTMAuB6fLc3FuntauaYYU9sPsESwFldf81npUW19BTqrL/J8D4 dIOhVxITpmb7ZEhjNy/3L6BhUa7nsQXleLC7PfFQu6lAb9Y+Ia9fn0Sgy nSGFY3PS9OvDz25bQmceMyrTBwcaqiah3A3AfBgbmrRksPpFalwAcNp84 c5/7GW7vtGZXq86XFvNuBCwpmTG/St/L+qch0m0GN6VJuLbeZZ0xJIMFb C8Jz192x5YloOt24grbTmqbY6ZEXPvwPG9yuELp0vlRAjjUPfBQRT67zd Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10581"; a="310232291" X-IronPort-AV: E=Sophos;i="5.96,304,1665471600"; d="scan'208";a="310232291" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jan 2023 01:30:13 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10581"; a="779921070" X-IronPort-AV: E=Sophos;i="5.96,304,1665471600"; d="scan'208";a="779921070" Received: from joe-255.igk.intel.com (HELO localhost) ([172.22.229.67]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jan 2023 01:30:08 -0800 Date: Fri, 6 Jan 2023 10:30:06 +0100 From: Stanislaw Gruszka To: Jiasheng Jiang Cc: jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com, tvrtko.ursulin@linux.intel.com, airlied@gmail.com, daniel@ffwll.ch, ville.syrjala@linux.intel.com, manasi.d.navare@intel.com, stanislav.lisovskiy@intel.com, lucas.demarchi@intel.com, intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: Re: [PATCH] drm/i915: Add missing check and destroy for alloc_workqueue Message-ID: <20230106093006.GA1586324@linux.intel.com> References: <20230106090934.6348-1-jiasheng@iscas.ac.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230106090934.6348-1-jiasheng@iscas.ac.cn> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 06, 2023 at 05:09:34PM +0800, Jiasheng Jiang wrote: > Add checks for the return value of alloc_workqueue and > alloc_ordered_workqueue as they may return NULL pointer and cause NULL > pointer dereference. > Moreover, destroy them when fails later in order to avoid memory leak. > Because in `drivers/gpu/drm/i915/i915_driver.c`, if > intel_modeset_init_noirq fails, its workqueues will not be destroyed. > > Fixes: c26a058680dc ("drm/i915: Use a high priority wq for nonblocking plane updates") > Fixes: 757fffcfdffb ("drm/i915: Put all non-blocking modesets onto an ordered wq") > Signed-off-by: Jiasheng Jiang Reviewed-by: Stanislaw Gruszka > drivers/gpu/drm/i915/display/intel_display.c | 21 ++++++++++++++++---- > 1 file changed, 17 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c > index 6c2686ecb62a..58f6840d6bd8 100644 > --- a/drivers/gpu/drm/i915/display/intel_display.c > +++ b/drivers/gpu/drm/i915/display/intel_display.c > @@ -8655,26 +8655,35 @@ int intel_modeset_init_noirq(struct drm_i915_private *i915) > intel_dmc_ucode_init(i915); > > i915->display.wq.modeset = alloc_ordered_workqueue("i915_modeset", 0); > + if (!i915->display.wq.modeset) { > + ret = -ENOMEM; > + goto cleanup_vga_client_pw_domain_dmc; > + } > + > i915->display.wq.flip = alloc_workqueue("i915_flip", WQ_HIGHPRI | > WQ_UNBOUND, WQ_UNBOUND_MAX_ACTIVE); > + if (!i915->display.wq.flip) { > + ret = -ENOMEM; > + goto cleanup_modeset; > + } > > intel_mode_config_init(i915); > > ret = intel_cdclk_init(i915); > if (ret) > - goto cleanup_vga_client_pw_domain_dmc; > + goto cleanup_flip; > > ret = intel_color_init(i915); > if (ret) > - goto cleanup_vga_client_pw_domain_dmc; > + goto cleanup_flip; > > ret = intel_dbuf_init(i915); > if (ret) > - goto cleanup_vga_client_pw_domain_dmc; > + goto cleanup_flip; > > ret = intel_bw_init(i915); > if (ret) > - goto cleanup_vga_client_pw_domain_dmc; > + goto cleanup_flip; > > init_llist_head(&i915->display.atomic_helper.free_list); > INIT_WORK(&i915->display.atomic_helper.free_work, > @@ -8686,6 +8695,10 @@ int intel_modeset_init_noirq(struct drm_i915_private *i915) > > return 0; > > +cleanup_flip: > + destroy_workqueue(i915->display.wq.flip); > +cleanup_modeset: > + destroy_workqueue(i915->display.wq.modeset); > cleanup_vga_client_pw_domain_dmc: > intel_dmc_ucode_fini(i915); > intel_power_domains_driver_remove(i915); > -- > 2.25.1 >