From patchwork Mon Nov 16 20:38:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Wunner X-Patchwork-Id: 7630611 Return-Path: X-Original-To: patchwork-platform-driver-x86@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8B3299F392 for ; Mon, 16 Nov 2015 20:51:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 94B89204AD for ; Mon, 16 Nov 2015 20:51:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A6456204AB for ; Mon, 16 Nov 2015 20:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752419AbbKPUvS (ORCPT ); Mon, 16 Nov 2015 15:51:18 -0500 Received: from mailout1.hostsharing.net ([83.223.95.204]:33565 "EHLO mailout1.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752446AbbKPUvQ (ORCPT ); Mon, 16 Nov 2015 15:51:16 -0500 X-Greylist: delayed 411 seconds by postgrey-1.27 at vger.kernel.org; Mon, 16 Nov 2015 15:51:16 EST Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mailout1.hostsharing.net (Postfix) with ESMTPS id 84557101B2EED; Mon, 16 Nov 2015 21:44:23 +0100 (CET) Received: from localhost (6-38-90-81.adsl.cmo.de [81.90.38.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by h08.hostsharing.net (Postfix) with ESMTPSA id 32B44603DB40; Mon, 16 Nov 2015 21:44:22 +0100 (CET) X-Mailbox-Line: From 3e4150dc6507efe64cf8c3e03e24702c97565866 Mon Sep 17 00:00:00 2001 Message-Id: <3e4150dc6507efe64cf8c3e03e24702c97565866.1447097319.git.lukas@wunner.de> In-Reply-To: References: From: Lukas Wunner Date: Mon, 16 Nov 2015 21:38:40 +0100 Subject: [PATCH 1/1] apple-gmux: Assign apple_gmux_data before registering To: Darren Hart Cc: Matthew Garrett , dri-devel@lists.freedesktop.org, platform-driver-x86@vger.kernel.org Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matthew Garrett Registering the handler after both GPUs will trigger a DDC switch for connector reprobing. This will oops if apple_gmux_data hasn't already been assigned. Reorder the code to do that. [Lukas: More generally, this commit fixes a race condition that is triggered by invoking a handler callback between the call to vga_switcheroo_register_handler() and the assignment of apple_gmux_data.] Tested-by: Pierre Moreau [MBP 5,3 2009 nvidia MCP79 + G96 pre-retina 15"] Tested-by: Paul Hordiienko [MBP 6,2 2010 intel ILK + nvidia GT216 pre-retina 15"] Tested-by: Lukas Wunner [MBP 9,1 2012 intel IVB + nvidia GK107 pre-retina 15"] Tested-by: William Brown [MBP 8,2 2011 intel SNB + amd turks pre-retina 15"] Tested-by: Bruno Bierbaumer [MBP 11,3 2013 intel HSW + nvidia GK107 retina 15"] Signed-off-by: Matthew Garrett Reviewed-by: Lukas Wunner Signed-off-by: Lukas Wunner --- drivers/platform/x86/apple-gmux.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple-gmux.c index 976efeb..aa58d41 100644 --- a/drivers/platform/x86/apple-gmux.c +++ b/drivers/platform/x86/apple-gmux.c @@ -588,18 +588,20 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) gmux_data->gpe = -1; } + apple_gmux_data = gmux_data; + init_completion(&gmux_data->powerchange_done); + gmux_enable_interrupts(gmux_data); + if (vga_switcheroo_register_handler(&gmux_handler)) { ret = -ENODEV; goto err_register_handler; } - init_completion(&gmux_data->powerchange_done); - apple_gmux_data = gmux_data; - gmux_enable_interrupts(gmux_data); - return 0; err_register_handler: + gmux_disable_interrupts(gmux_data); + apple_gmux_data = NULL; if (gmux_data->gpe >= 0) acpi_disable_gpe(NULL, gmux_data->gpe); err_enable_gpe: