diff mbox

[RFC,2/2] sound: ppc: keywest: drop using attach adapter

Message ID 1417711313-7257-3-git-send-email-wsa@the-dreams.de (mailing list archive)
State New, archived
Headers show

Commit Message

Wolfram Sang Dec. 4, 2014, 4:41 p.m. UTC
As we now have deferred probing, we can use a custom mechanism and
finally get rid of the legacy interface from the i2c core.

Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
---
 sound/ppc/keywest.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

Comments

Takashi Iwai Dec. 4, 2014, 4:58 p.m. UTC | #1
At Thu,  4 Dec 2014 17:41:53 +0100,
Wolfram Sang wrote:
> 
> As we now have deferred probing, we can use a custom mechanism and
> finally get rid of the legacy interface from the i2c core.
> 
> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
> ---
>  sound/ppc/keywest.c | 21 ++++++++++++++++++---
>  1 file changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/ppc/keywest.c b/sound/ppc/keywest.c
> index 0d1c27e911b8..a957f32368fa 100644
> --- a/sound/ppc/keywest.c
> +++ b/sound/ppc/keywest.c
> @@ -52,7 +52,7 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter)
>  		return -EINVAL;
>  
>  	if (strncmp(adapter->name, "mac-io", 6))
> -		return 0; /* ignored */
> +		return -EINVAL; /* ignored */
>  
>  	memset(&info, 0, sizeof(struct i2c_board_info));
>  	strlcpy(info.type, "keywest", I2C_NAME_SIZE);
> @@ -100,7 +100,6 @@ static struct i2c_driver keywest_driver = {
>  	.driver = {
>  		.name = "PMac Keywest Audio",
>  	},
> -	.attach_adapter = keywest_attach_adapter,
>  	.probe = keywest_probe,
>  	.remove = keywest_remove,
>  	.id_table = keywest_i2c_id,
> @@ -132,16 +131,32 @@ int snd_pmac_tumbler_post_init(void)
>  /* exported */
>  int snd_pmac_keywest_init(struct pmac_keywest *i2c)
>  {
> -	int err;
> +	struct i2c_adapter *adap;
> +	int err, i = 0;
>  
>  	if (keywest_ctx)
>  		return -EBUSY;
>  
> +	adap = i2c_get_adapter(0);
> +	if (!adap)
> +		return -EPROBE_DEFER;
> +
>  	keywest_ctx = i2c;
>  
>  	if ((err = i2c_add_driver(&keywest_driver))) {
>  		snd_printk(KERN_ERR "cannot register keywest i2c driver\n");
> +		i2c_put_adapter(adap);
>  		return err;
>  	}
> +
> +	/* We assume Macs have consecutive I2C bus numbers starting at 0 */
> +	while (adap) {
> +		err = keywest_attach_adapter(adap);
> +		if (!err)
> +			break;
> +		i2c_put_adapter(adap);
> +		adap = i2c_get_adapter(++i);
> +	}
> +
>  	return 0;

What if adap is NULL in the last while loop?  Isn't it supposed to
return an error?


thanks,

Takashi
Wolfram Sang Dec. 4, 2014, 5:46 p.m. UTC | #2
> > +
> > +	/* We assume Macs have consecutive I2C bus numbers starting at 0 */
> > +	while (adap) {
> > +		err = keywest_attach_adapter(adap);
> > +		if (!err)
> > +			break;
> > +		i2c_put_adapter(adap);
> > +		adap = i2c_get_adapter(++i);
> > +	}
> > +
> >  	return 0;
> 
> What if adap is NULL in the last while loop?  Isn't it supposed to
> return an error?

True, we probably should have something like

	return adap ? 0 : -ENODEV;

Thanks!
diff mbox

Patch

diff --git a/sound/ppc/keywest.c b/sound/ppc/keywest.c
index 0d1c27e911b8..a957f32368fa 100644
--- a/sound/ppc/keywest.c
+++ b/sound/ppc/keywest.c
@@ -52,7 +52,7 @@  static int keywest_attach_adapter(struct i2c_adapter *adapter)
 		return -EINVAL;
 
 	if (strncmp(adapter->name, "mac-io", 6))
-		return 0; /* ignored */
+		return -EINVAL; /* ignored */
 
 	memset(&info, 0, sizeof(struct i2c_board_info));
 	strlcpy(info.type, "keywest", I2C_NAME_SIZE);
@@ -100,7 +100,6 @@  static struct i2c_driver keywest_driver = {
 	.driver = {
 		.name = "PMac Keywest Audio",
 	},
-	.attach_adapter = keywest_attach_adapter,
 	.probe = keywest_probe,
 	.remove = keywest_remove,
 	.id_table = keywest_i2c_id,
@@ -132,16 +131,32 @@  int snd_pmac_tumbler_post_init(void)
 /* exported */
 int snd_pmac_keywest_init(struct pmac_keywest *i2c)
 {
-	int err;
+	struct i2c_adapter *adap;
+	int err, i = 0;
 
 	if (keywest_ctx)
 		return -EBUSY;
 
+	adap = i2c_get_adapter(0);
+	if (!adap)
+		return -EPROBE_DEFER;
+
 	keywest_ctx = i2c;
 
 	if ((err = i2c_add_driver(&keywest_driver))) {
 		snd_printk(KERN_ERR "cannot register keywest i2c driver\n");
+		i2c_put_adapter(adap);
 		return err;
 	}
+
+	/* We assume Macs have consecutive I2C bus numbers starting at 0 */
+	while (adap) {
+		err = keywest_attach_adapter(adap);
+		if (!err)
+			break;
+		i2c_put_adapter(adap);
+		adap = i2c_get_adapter(++i);
+	}
+
 	return 0;
 }