Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1393184ybx; Thu, 31 Oct 2019 09:57:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzGM7WmBmvxKwiKONER/GEisc8JV2MquqKTv2h0yZdsMwcLxAG1zLmpQb65pBc4Ewvm1+CH X-Received: by 2002:a17:906:e2cb:: with SMTP id gr11mr5212382ejb.205.1572541020035; Thu, 31 Oct 2019 09:57:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572541020; cv=none; d=google.com; s=arc-20160816; b=hVtMZ7RQEq14k7NAinlkSaYo+3Svt7xdPQKtLjDiZE5l1iObIxFQjX26JYe9xjn75C NScsmhQ4yXWjGTjl7FM5vkSuA+OtLMP1GZua2qMF5FeDkPH2dsD0U7Ls7+DQORNRHdtD PvpiGjp+RJQv2ZFu1s7hNUVh8K5JPREXFjz7lIqNE+HCOAGSxgkDp7htLesRjmkZlbhn gxHJNIeShFgQmues3k6ohJXqA/vHnImROgX3/ifEDLwE05eDNIEGPr9OxigjY01YiBuU Ac/qIKaheVkacvHtvREsoZ0RC/n4ntCAGbmqEcSld5mHhngJw+cyHtZ8XQBV+r+oKGH6 RmWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VzJ+ta9uiCcfkSuWNiQxyanbVG3Oujplc1fmj+I9jEY=; b=0qGDC8W2CPF28i0xyjlA/BYJ6WE6LS5QAyiZunvQKuyq6KJpGxudXkYlm5ElD+dS3s zGc3pJ1ZcBSON10kPGQdi1lg/0wisXV8mGj+XJviyPrnEe4zEguv90swvhVaOX+/Q9oN KglwMu6oWBIY0XYJ9+FTl2NQBOYdXCfTu5IJVINoUUgRGx7vOZadSEsBiYhqhEpMsAUU 99js4zK0o6Vx0qPVDOEF1E5H6v+FIF45G0P1itB8m3qoO6soiBHN/FZxdCdTSgW+7N0y M5R6shY/yYi787fLqre9G0DJrvNzQmj7XNDo1+UKH4jGBFvRmiGF+Y3yobTs7P0Kguzi YRFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="RIP6UX/m"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si5411692edv.82.2019.10.31.09.56.36; Thu, 31 Oct 2019 09:57:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="RIP6UX/m"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728750AbfJaQy6 (ORCPT + 99 others); Thu, 31 Oct 2019 12:54:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:52198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728561AbfJaQy5 (ORCPT ); Thu, 31 Oct 2019 12:54:57 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EF0952087F; Thu, 31 Oct 2019 16:54:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572540896; bh=OZrErChAGs00qAHYyPBCWqxK7o5kPOgyp3wi9HrAQIc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=RIP6UX/m7Jn92SmAMwX5+rlm4MZS5frptt7p6ev7IHTt3paaicKA0sAikpAwyGmd/ doxRRQrIO8OlGIcICs0GTNfSzK0bWMHzVQl2ktvhjFkUdhYgCWHF6ZtBYHWWaVBIaj VV4kg3eooa9hxr+lt0Js6kDMp7XGsZH5sOgKy4ow= Date: Thu, 31 Oct 2019 16:54:51 +0000 From: Will Deacon To: Michel =?iso-8859-1?Q?D=E4nzer?= Cc: amd-gfx@lists.freedesktop.org, David Airlie , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Nicolas Waisman , Alex Deucher , Christian =?iso-8859-1?Q?K=F6nig?= Subject: Re: [PATCH] drm/radeon: Handle workqueue allocation failure Message-ID: <20191031165450.GA28461@willie-the-truck> References: <20191025110450.10474-1-will@kernel.org> <5d6a88a2-2719-a859-04df-10b0d893ff39@daenzer.net> <20191025161804.GA12335@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 25, 2019 at 06:20:01PM +0200, Michel D?nzer wrote: > On 2019-10-25 6:18 p.m., Will Deacon wrote: > > On Fri, Oct 25, 2019 at 06:06:26PM +0200, Michel D?nzer wrote: > >> On 2019-10-25 1:04 p.m., Will Deacon wrote: > >>> In the highly unlikely event that we fail to allocate the "radeon-crtc" > >>> workqueue, we should bail cleanly rather than blindly march on with a > >>> NULL pointer installed for the 'flip_queue' field of the 'radeon_crtc' > >>> structure. > >>> > >>> This was reported previously by Nicolas, but I don't think his fix was > >>> correct: > >> > >> Neither is this one I'm afraid. See my feedback on > >> https://patchwork.freedesktop.org/patch/331534/ . > > > > Thanks. Although I agree with you wrt the original patch, I don't think > > the workqueue allocation failure is distinguishable from the CRTC allocation > > failure with my patch. Are you saying that the error path there is broken > > too? > > The driver won't actually work if radeon_crtc_init bails silently, it'll > just fall over at some later point. Ok, so how about fleshing it out as per below? Will --->8 diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c index e81b01f8db90..177acee06620 100644 --- a/drivers/gpu/drm/radeon/radeon_display.c +++ b/drivers/gpu/drm/radeon/radeon_display.c @@ -668,21 +668,29 @@ static const struct drm_crtc_funcs radeon_crtc_funcs = { .page_flip_target = radeon_crtc_page_flip_target, }; -static void radeon_crtc_init(struct drm_device *dev, int index) +static int radeon_crtc_init(struct drm_device *dev, int index) { struct radeon_device *rdev = dev->dev_private; struct radeon_crtc *radeon_crtc; + struct workqueue_struct *wq; int i; radeon_crtc = kzalloc(sizeof(struct radeon_crtc) + (RADEONFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); if (radeon_crtc == NULL) - return; + return -ENOMEM; + + wq = alloc_workqueue("radeon-crtc", WQ_HIGHPRI, 0); + if (unlikely(!wq)) { + kfree(radeon_crtc); + return - ENOMEM; + } drm_crtc_init(dev, &radeon_crtc->base, &radeon_crtc_funcs); drm_mode_crtc_set_gamma_size(&radeon_crtc->base, 256); radeon_crtc->crtc_id = index; - radeon_crtc->flip_queue = alloc_workqueue("radeon-crtc", WQ_HIGHPRI, 0); + radeon_crtc->flip_queue = wq; + rdev->mode_info.crtcs[index] = radeon_crtc; if (rdev->family >= CHIP_BONAIRE) { @@ -711,6 +719,8 @@ static void radeon_crtc_init(struct drm_device *dev, int index) radeon_atombios_init_crtc(dev, radeon_crtc); else radeon_legacy_init_crtc(dev, radeon_crtc); + + return 0; } static const char *encoder_names[38] = { @@ -1602,9 +1612,8 @@ int radeon_modeset_init(struct radeon_device *rdev) rdev->ddev->mode_config.fb_base = rdev->mc.aper_base; ret = radeon_modeset_create_props(rdev); - if (ret) { - return ret; - } + if (ret) + goto err_drm_mode_config_cleanup; /* init i2c buses */ radeon_i2c_init(rdev); @@ -1617,7 +1626,9 @@ int radeon_modeset_init(struct radeon_device *rdev) /* allocate crtcs */ for (i = 0; i < rdev->num_crtc; i++) { - radeon_crtc_init(rdev->ddev, i); + ret = radeon_crtc_init(rdev->ddev, i); + if (ret) + goto err_drm_mode_config_cleanup; } /* okay we should have all the bios connectors */ @@ -1645,6 +1656,10 @@ int radeon_modeset_init(struct radeon_device *rdev) ret = radeon_pm_late_init(rdev); return 0; + +err_drm_mode_config_cleanup: + drm_mode_config_cleanup(rdev->ddev); + return ret; } void radeon_modeset_fini(struct radeon_device *rdev)