Skip to content

Commit 38b17af

Browse files
author
Wolfram Sang
committed
macintosh: therm_windtunnel: fix regression when instantiating devices
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: 3e7bed5 ("macintosh: therm_windtunnel: drop using attach_adapter") Link: https://bugzilla.kernel.org/show_bug.cgi?id=201723 Reported-by: Erhard Furtner <[email protected]> Tested-by: Erhard Furtner <[email protected]> Acked-by: Michael Ellerman <[email protected]> (powerpc) Signed-off-by: Wolfram Sang <[email protected]> Cc: [email protected] # v4.19+
1 parent 54498e8 commit 38b17af

File tree

1 file changed

+31
-21
lines changed

1 file changed

+31
-21
lines changed

drivers/macintosh/therm_windtunnel.c

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,11 @@ static int control_loop(void *dummy)
300300
/* i2c probing and setup */
301301
/************************************************************************/
302302

303-
static int
304-
do_attach( struct i2c_adapter *adapter )
303+
static void do_attach(struct i2c_adapter *adapter)
305304
{
305+
struct i2c_board_info info = { };
306+
struct device_node *np;
307+
306308
/* scan 0x48-0x4f (DS1775) and 0x2c-2x2f (ADM1030) */
307309
static const unsigned short scan_ds1775[] = {
308310
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
@@ -313,25 +315,24 @@ do_attach( struct i2c_adapter *adapter )
313315
I2C_CLIENT_END
314316
};
315317

316-
if( strncmp(adapter->name, "uni-n", 5) )
317-
return 0;
318-
319-
if( !x.running ) {
320-
struct i2c_board_info info;
318+
if (x.running || strncmp(adapter->name, "uni-n", 5))
319+
return;
321320

322-
memset(&info, 0, sizeof(struct i2c_board_info));
323-
strlcpy(info.type, "therm_ds1775", I2C_NAME_SIZE);
321+
np = of_find_compatible_node(adapter->dev.of_node, NULL, "MAC,ds1775");
322+
if (np) {
323+
of_node_put(np);
324+
} else {
325+
strlcpy(info.type, "MAC,ds1775", I2C_NAME_SIZE);
324326
i2c_new_probed_device(adapter, &info, scan_ds1775, NULL);
327+
}
325328

326-
strlcpy(info.type, "therm_adm1030", I2C_NAME_SIZE);
329+
np = of_find_compatible_node(adapter->dev.of_node, NULL, "MAC,adm1030");
330+
if (np) {
331+
of_node_put(np);
332+
} else {
333+
strlcpy(info.type, "MAC,adm1030", I2C_NAME_SIZE);
327334
i2c_new_probed_device(adapter, &info, scan_adm1030, NULL);
328-
329-
if( x.thermostat && x.fan ) {
330-
x.running = 1;
331-
x.poll_task = kthread_run(control_loop, NULL, "g4fand");
332-
}
333335
}
334-
return 0;
335336
}
336337

337338
static int
@@ -404,8 +405,8 @@ attach_thermostat( struct i2c_client *cl )
404405
enum chip { ds1775, adm1030 };
405406

406407
static const struct i2c_device_id therm_windtunnel_id[] = {
407-
{ "therm_ds1775", ds1775 },
408-
{ "therm_adm1030", adm1030 },
408+
{ "MAC,ds1775", ds1775 },
409+
{ "MAC,adm1030", adm1030 },
409410
{ }
410411
};
411412
MODULE_DEVICE_TABLE(i2c, therm_windtunnel_id);
@@ -414,18 +415,27 @@ static int
414415
do_probe(struct i2c_client *cl, const struct i2c_device_id *id)
415416
{
416417
struct i2c_adapter *adapter = cl->adapter;
418+
int ret = 0;
417419

418420
if( !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA
419421
| I2C_FUNC_SMBUS_WRITE_BYTE) )
420422
return 0;
421423

422424
switch (id->driver_data) {
423425
case adm1030:
424-
return attach_fan( cl );
426+
ret = attach_fan(cl);
427+
break;
425428
case ds1775:
426-
return attach_thermostat(cl);
429+
ret = attach_thermostat(cl);
430+
break;
427431
}
428-
return 0;
432+
433+
if (!x.running && x.thermostat && x.fan) {
434+
x.running = 1;
435+
x.poll_task = kthread_run(control_loop, NULL, "g4fand");
436+
}
437+
438+
return ret;
429439
}
430440

431441
static struct i2c_driver g4fan_driver = {

0 commit comments

Comments
 (0)