All of lore.kernel.org
 help / color / mirror / Atom feed
From: khali@linux-fr.org (Jean Delvare)
To: lm-sensors@vger.kernel.org
Subject: [lm-sensors] [RFC PATCH 2.6.18-rc4-mm1] hwmon: unchecked return
Date: Tue, 15 Aug 2006 07:37:12 +0000	[thread overview]
Message-ID: <20060815093712.e2e5561a.khali@linux-fr.org> (raw)
In-Reply-To: <20060814020407.GA3327@jupiter.solarsys.private>

Hi David,

> I added some return value checks in w83627ehf_detect(). This is called
> from i2c_isa_add_driver using driver->attach_adapter(&isa_adapter). So
> I returned an error from w83627ehf_detect(), and was surprised to see
> that the module silently succeeded, without fully creating the
> w83627ehf sysfs interface. I looked deeper and found that
> i2c_isa_add_driver() does not check the return value when calling its
> driver->attach_adapter(). i2c_isa_add_driver() is called from
> sensors_w83627ehf_init(), which is the module_init function.

Good catch, we should indeed check the return value.

This code was copied from i2c-core, where the value returned by
driver->attach_adapter() is ignored as well. There's even a comment:
"We ignore the return code; if it fails, too bad". Sigh. The problem in
i2c-core is that attach_adapter() will be called in a loop, on each
available driver (when calling i2c_add_adapter) or each available
adapter (when calling i2c_add_driver). We can't stop if one call fail,
that wouldn't be fair for the others which may still succeed. The proper
fix is to switch to the device driver model...

In the i2c-isa case things are much more simple, we have a single call
so failing on error sounds good.

> I have attached a very short patch for drivers/i2c/busses/i2c-isa.c
> which should fix the problem. Instead of returning 0, it returns the
> result of driver->attach_adapter().

> diff -ur linux-2.6.18-rc4/drivers/i2c/busses/i2c-isa.c linux-2.6.18-rc4/drivers/i2c/busses/i2c-isa.c
> --- linux-2.6.18-rc4/drivers/i2c/busses/i2c-isa.c	2006-08-14 17:48:28.000000000 -0700
> +++ linux-2.6.18-rc4/drivers/i2c/busses/i2c-isa.c	2006-08-14 17:52:04.000000000 -0700
> @@ -89,9 +89,7 @@
>  	dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->driver.name);
>  
>  	/* Now look for clients */
> -	driver->attach_adapter(&isa_adapter);
> -
> -	return 0;
> +	return driver->attach_adapter(&isa_adapter);
>  }

That's not enough, unfortunately. In case of error you must unregister
the driver before returning. I also think we should print some message
on error. Care to send an updated patch?

> However, this may cause a great deal of unexpected grief, considering
> how many drivers use this function.

Not that many (11), and they are all hardware monitoring drivers.

-- 
Jean Delvare


  parent reply	other threads:[~2006-08-15  7:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-14  2:04 [lm-sensors] [RFC PATCH 2.6.18-rc4-mm1] hwmon: unchecked return Mark M. Hoffman
2006-08-14 13:02 ` Jean Delvare
2006-08-15  0:09 ` David Hubbard
2006-08-15  3:14 ` Mark M. Hoffman
2006-08-15  3:17 ` Mark M. Hoffman
2006-08-15  7:37 ` Jean Delvare [this message]
2006-08-15  8:01 ` Jean Delvare
2006-08-16 22:00 ` David Hubbard
2006-08-18  9:18 ` Jean Delvare
2006-08-20  2:15 ` David Hubbard
2006-08-20 12:23 ` Jean Delvare
2006-08-20 21:23 ` David Hubbard
2006-08-21  8:15 ` Jean Delvare
2006-08-22  5:21 ` David Hubbard
2006-08-23  6:50 ` Jean Delvare
2006-08-28  2:07 ` David Hubbard
2006-08-30  7:10 ` Jean Delvare
2006-09-01 10:21 ` Jean Delvare
2006-09-01 18:20 ` David Hubbard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060815093712.e2e5561a.khali@linux-fr.org \
    --to=khali@linux-fr.org \
    --cc=lm-sensors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.