Received: by 2002:a17:90a:9307:0:0:0:0 with SMTP id p7csp3961160pjo; Tue, 3 Mar 2020 10:08:21 -0800 (PST) X-Google-Smtp-Source: ADFU+vvkU/vBsKj8UPZeCl+F9m6nbQYVH1oLPeG16Ub/ZM696VCwuEqw3jNDawF/sAL4A6tvzZuU X-Received: by 2002:a05:6830:181:: with SMTP id q1mr4212535ota.335.1583258901041; Tue, 03 Mar 2020 10:08:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583258901; cv=none; d=google.com; s=arc-20160816; b=SphCOdBSX7/4HItfQIR83s7UXc4lewpJrXF/Ekwj5XujtcEHo5yGwtxTNJ1YJaQeeh YJLJGpMo9Z4x2eTeG/gYrA9T0K1JnMsK5VMAXSYSG+9di0U53jqxH8EpxZiQx41xu7sW anQepl+UUuavF5uXm5JiteYJWOR28WP+mwV+rm0pvg4UwtXXjuV3PB9MpIOgABhvxBC8 FGqykJWaLP1oQ7tmZ8sehIjBdGLMoRDUBBxYngcA5xoLtmJ3FNZY9jsoSAS2lDsRbcBf mNDzs8xXh3UYZdfI37vDTzFh8I2b9EVLVdeLkmpydW78LD2q97XUUfMGL7GUAOJN15FM Dj+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=B+AEz0CDKk74TPa28gDGiF2ZGXpaSA5OIBPwIvaz2wA=; b=Qn7eJcX4wbHsl4abAVs1KUqJYzQ/3DDKeHqGyCwLYW8jqES59nTQUSAhKmKBPNadXM XuSWnb+uE1NK7/fAAfg5KuI4zZmtGbUS9f59ElrOc3Crwb4svJ5Srt7U5dFPYXR+TLvb KCbIR9Q4PAcwxEoWg7ng1hnL4GV1/PNhv3r58vKI3YL6QsNYGVxrYyG2LszDgqwByqZO H3j2y0h4sShPl5txNatpqDmFiYtDAPeOtqUsUBfLUx1oBKewi1RoHQO9/vEr5fENr0Eu w2g9HE7ikznN0NmonjMW40VroqhhB/q664IhcSG8v/Qu6mEwZKasG/VwwBvYkO4Qvy7k elcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pfdfi5Mt; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k16si8302321oiw.128.2020.03.03.10.08.08; Tue, 03 Mar 2020 10:08:21 -0800 (PST) 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=pfdfi5Mt; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388059AbgCCSG7 (ORCPT + 99 others); Tue, 3 Mar 2020 13:06:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:37124 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732718AbgCCRz3 (ORCPT ); Tue, 3 Mar 2020 12:55:29 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 719C4206D5; Tue, 3 Mar 2020 17:55:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583258128; bh=toAKJpVcK8AmIRqax8RohZ3VZLNcWfijpolDJB41s/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pfdfi5MtK4ALywCP3kNrMbclBpy292C6gzMPcySN59ehouukPE3T2hVG8LK4i1ZaI UkDaeWB7oTtWuENMFN80GUyvDgQUMXxhw+qe41BDQsshTJ9mmV8vrl2ELNTGxXQJaS g+S8KEjnCSEH4qdOiqHQ9TAK1gT37Tk3LK5Fjkgw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Erhard Furtner , Wolfram Sang , Michael Ellerman , stable@kernel.org Subject: [PATCH 5.4 081/152] macintosh: therm_windtunnel: fix regression when instantiating devices Date: Tue, 3 Mar 2020 18:42:59 +0100 Message-Id: <20200303174311.753116244@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200303174302.523080016@linuxfoundation.org> References: <20200303174302.523080016@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wolfram Sang commit 38b17afb0ebb9ecd41418d3c08bcf9198af4349d upstream. Removing attach_adapter from this driver caused a regression for at least some machines. Those machines had the sensors described in their DT, too, so they didn't need manual creation of the sensor devices. The old code worked, though, because manual creation came first. Creation of DT devices then failed later and caused error logs, but the sensors worked nonetheless because of the manually created devices. When removing attach_adaper, manual creation now comes later and loses the race. The sensor devices were already registered via DT, yet with another binding, so the driver could not be bound to it. This fix refactors the code to remove the race and only manually creates devices if there are no DT nodes present. Also, the DT binding is updated to match both, the DT and manually created devices. Because we don't know which device creation will be used at runtime, the code to start the kthread is moved to do_probe() which will be called by both methods. Fixes: 3e7bed52719d ("macintosh: therm_windtunnel: drop using attach_adapter") Link: https://bugzilla.kernel.org/show_bug.cgi?id=201723 Reported-by: Erhard Furtner Tested-by: Erhard Furtner Acked-by: Michael Ellerman (powerpc) Signed-off-by: Wolfram Sang Cc: stable@kernel.org # v4.19+ Signed-off-by: Greg Kroah-Hartman --- drivers/macintosh/therm_windtunnel.c | 52 ++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 21 deletions(-) --- a/drivers/macintosh/therm_windtunnel.c +++ b/drivers/macintosh/therm_windtunnel.c @@ -300,9 +300,11 @@ static int control_loop(void *dummy) /* i2c probing and setup */ /************************************************************************/ -static int -do_attach( struct i2c_adapter *adapter ) +static void do_attach(struct i2c_adapter *adapter) { + struct i2c_board_info info = { }; + struct device_node *np; + /* scan 0x48-0x4f (DS1775) and 0x2c-2x2f (ADM1030) */ static const unsigned short scan_ds1775[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, @@ -313,25 +315,24 @@ do_attach( struct i2c_adapter *adapter ) I2C_CLIENT_END }; - if( strncmp(adapter->name, "uni-n", 5) ) - return 0; - - if( !x.running ) { - struct i2c_board_info info; + if (x.running || strncmp(adapter->name, "uni-n", 5)) + return; - memset(&info, 0, sizeof(struct i2c_board_info)); - strlcpy(info.type, "therm_ds1775", I2C_NAME_SIZE); + np = of_find_compatible_node(adapter->dev.of_node, NULL, "MAC,ds1775"); + if (np) { + of_node_put(np); + } else { + strlcpy(info.type, "MAC,ds1775", I2C_NAME_SIZE); i2c_new_probed_device(adapter, &info, scan_ds1775, NULL); + } - strlcpy(info.type, "therm_adm1030", I2C_NAME_SIZE); + np = of_find_compatible_node(adapter->dev.of_node, NULL, "MAC,adm1030"); + if (np) { + of_node_put(np); + } else { + strlcpy(info.type, "MAC,adm1030", I2C_NAME_SIZE); i2c_new_probed_device(adapter, &info, scan_adm1030, NULL); - - if( x.thermostat && x.fan ) { - x.running = 1; - x.poll_task = kthread_run(control_loop, NULL, "g4fand"); - } } - return 0; } static int @@ -404,8 +405,8 @@ out: enum chip { ds1775, adm1030 }; static const struct i2c_device_id therm_windtunnel_id[] = { - { "therm_ds1775", ds1775 }, - { "therm_adm1030", adm1030 }, + { "MAC,ds1775", ds1775 }, + { "MAC,adm1030", adm1030 }, { } }; MODULE_DEVICE_TABLE(i2c, therm_windtunnel_id); @@ -414,6 +415,7 @@ static int do_probe(struct i2c_client *cl, const struct i2c_device_id *id) { struct i2c_adapter *adapter = cl->adapter; + int ret = 0; if( !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_WRITE_BYTE) ) @@ -421,11 +423,19 @@ do_probe(struct i2c_client *cl, const st switch (id->driver_data) { case adm1030: - return attach_fan( cl ); + ret = attach_fan(cl); + break; case ds1775: - return attach_thermostat(cl); + ret = attach_thermostat(cl); + break; } - return 0; + + if (!x.running && x.thermostat && x.fan) { + x.running = 1; + x.poll_task = kthread_run(control_loop, NULL, "g4fand"); + } + + return ret; } static struct i2c_driver g4fan_driver = {