Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1471384

Re: [PATCH v2] i2c: move locking operations to their own struct

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.unit0.net!news.panservice.it!bofh.it!news.nic.it!robomod
From Daniel Vetter <daniel@ffwll.ch>
Newsgroups linux.kernel
Subject Re: [PATCH v2] i2c: move locking operations to their own struct
Date Sun, 28 Aug 2016 18:10:02 +0200
Message-ID <sbaOK-3Su-9@gated-at.bofh.it> (permalink)
References <sbaOK-3Su-11@gated-at.bofh.it>
X-Original-To Peter Rosin <peda@axentia.se>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=sender:date:from:to:cc:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=HJLIKgOa1JIChOZ8wZjozZBht35YS+/rWpghhjwbf/E=; b=Un1vrGa8KIYAA3RYvXZWSlO6Qn4wUQ93JJivfFNWmq86cseSiUn+GYT97XwIe3itBB SHLb8ZbNT2kQXfHCbJFy8019uVzB8hexN1Z6DVYDslZ2D87s/i70XbnnHxnyx5/qGPzw v7MY2wwSpbQrQk5PKUeFusjLX18hY031wuYBo=
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=HJLIKgOa1JIChOZ8wZjozZBht35YS+/rWpghhjwbf/E=; b=fdJ9s1wokzhuc9FSIutQ2ausMER1N2w4jFw3ZPf/1X+UunIwY3Lk9BFwCUXf6L2x3+ EJLAS5v9Ip5GiSmrDj0XlQpUqfQS3KODwzp4VoEDhmrhvQe0fYb0j4+GKhu8cwxLb0Gt viSWv97FBTgeiwE+TA9ORM2o2i+x9bnrFcOjhC/LIvrSoD5OahHOs0HMBEuTTlGa38m0 Rlb6UOwh289JvCyKbinbiO9RwK8UnbPPBbKrdqL+luxcnE03Rl81Xha1tQRG+7FJiBiC 5IfDBnoDoUVEUrzmcZso6Y2s/gbh95Qq8+ly7m7+9ECOW6q7zpjt0KNkN4p4B212QxIb VKGg==
X-Gm-Message-State AE9vXwOsE0I4IGb+33vBAEYlqbrmUHlIT5+9MhlRE2bTqjcw9W4x2anN2MA7H4capLLwJg==
X-Received by 10.28.126.75 with SMTP id z72mr7069355wmc.74.1472400384586; Sun, 28 Aug 2016 09:06:24 -0700 (PDT)
Mail-Followup-To Peter Rosin <peda@axentia.se>, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, dri-devel@lists.freedesktop.org, Wolfram Sang <wsa@the-dreams.de>
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
X-Operating-System Linux phenom 4.6.0-1-amd64
User-Agent Mutt/1.6.0 (2016-04-01)
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 213
Organization linux.* mail to news gateway
X-Original-Cc linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, dri-devel@lists.freedesktop.org, Wolfram Sang <wsa@the-dreams.de>
X-Original-Date Sun, 28 Aug 2016 18:06:21 +0200
X-Original-Message-ID <20160828160621.GX10980@phenom.ffwll.local>
X-Original-References <1472159221-10807-1-git-send-email-peda@axentia.se>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1471384

Show key headers only | View raw


On Thu, Aug 25, 2016 at 11:07:01PM +0200, Peter Rosin wrote:
> This makes it trivial to constify them, so do that.
> 
> Signed-off-by: Peter Rosin <peda@axentia.se>

Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>

Feel free to merge through i2c tree.
-Daniel

> ---
>  drivers/gpu/drm/drm_dp_helper.c | 10 +++++++---
>  drivers/i2c/i2c-core.c          | 13 ++++++++-----
>  drivers/i2c/i2c-mux.c           | 25 ++++++++++++++++---------
>  include/linux/i2c.h             | 25 ++++++++++++++++++-------
>  4 files changed, 49 insertions(+), 24 deletions(-)
> 
> Changes since v1:
> 
> - Also fix the user in drivers/gpu (only compile-tested, but
>   it's simple enough...)
> 
> This takes care of the 0-day splat reported in:
> http://marc.info/?l=linux-i2c&m=147215193023544&w=2
> 
> Cheers,
> Peter
> 
> diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c
> index eae5ef963cb7..2bd064493ae7 100644
> --- a/drivers/gpu/drm/drm_dp_helper.c
> +++ b/drivers/gpu/drm/drm_dp_helper.c
> @@ -790,6 +790,12 @@ static void unlock_bus(struct i2c_adapter *i2c, unsigned int flags)
>  	mutex_unlock(&i2c_to_aux(i2c)->hw_mutex);
>  }
>  
> +static const struct i2c_lock_operations drm_dp_i2c_lock_ops = {
> +	.lock_bus = lock_bus,
> +	.trylock_bus = trylock_bus,
> +	.unlock_bus = unlock_bus,
> +};
> +
>  /**
>   * drm_dp_aux_init() - minimally initialise an aux channel
>   * @aux: DisplayPort AUX channel
> @@ -807,9 +813,7 @@ void drm_dp_aux_init(struct drm_dp_aux *aux)
>  	aux->ddc.algo_data = aux;
>  	aux->ddc.retries = 3;
>  
> -	aux->ddc.lock_bus = lock_bus;
> -	aux->ddc.trylock_bus = trylock_bus;
> -	aux->ddc.unlock_bus = unlock_bus;
> +	aux->ddc.lock_ops = &drm_dp_i2c_lock_ops;
>  }
>  EXPORT_SYMBOL(drm_dp_aux_init);
>  
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 56e50ca905ba..0bdda24a10b2 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -1691,6 +1691,12 @@ static int __process_new_adapter(struct device_driver *d, void *data)
>  	return i2c_do_add_adapter(to_i2c_driver(d), data);
>  }
>  
> +static const struct i2c_lock_operations i2c_adapter_lock_ops = {
> +	.lock_bus =    i2c_adapter_lock_bus,
> +	.trylock_bus = i2c_adapter_trylock_bus,
> +	.unlock_bus =  i2c_adapter_unlock_bus,
> +};
> +
>  static int i2c_register_adapter(struct i2c_adapter *adap)
>  {
>  	int res = -EINVAL;
> @@ -1710,11 +1716,8 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
>  		goto out_list;
>  	}
>  
> -	if (!adap->lock_bus) {
> -		adap->lock_bus = i2c_adapter_lock_bus;
> -		adap->trylock_bus = i2c_adapter_trylock_bus;
> -		adap->unlock_bus = i2c_adapter_unlock_bus;
> -	}
> +	if (!adap->lock_ops)
> +		adap->lock_ops = &i2c_adapter_lock_ops;
>  
>  	rt_mutex_init(&adap->bus_lock);
>  	rt_mutex_init(&adap->mux_lock);
> diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
> index 764f195795e4..14741ff31041 100644
> --- a/drivers/i2c/i2c-mux.c
> +++ b/drivers/i2c/i2c-mux.c
> @@ -263,6 +263,18 @@ struct i2c_mux_core *i2c_mux_alloc(struct i2c_adapter *parent,
>  }
>  EXPORT_SYMBOL_GPL(i2c_mux_alloc);
>  
> +static const struct i2c_lock_operations i2c_mux_lock_ops = {
> +	.lock_bus =    i2c_mux_lock_bus,
> +	.trylock_bus = i2c_mux_trylock_bus,
> +	.unlock_bus =  i2c_mux_unlock_bus,
> +};
> +
> +static const struct i2c_lock_operations i2c_parent_lock_ops = {
> +	.lock_bus =    i2c_parent_lock_bus,
> +	.trylock_bus = i2c_parent_trylock_bus,
> +	.unlock_bus =  i2c_parent_unlock_bus,
> +};
> +
>  int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
>  			u32 force_nr, u32 chan_id,
>  			unsigned int class)
> @@ -312,15 +324,10 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
>  	priv->adap.retries = parent->retries;
>  	priv->adap.timeout = parent->timeout;
>  	priv->adap.quirks = parent->quirks;
> -	if (muxc->mux_locked) {
> -		priv->adap.lock_bus = i2c_mux_lock_bus;
> -		priv->adap.trylock_bus = i2c_mux_trylock_bus;
> -		priv->adap.unlock_bus = i2c_mux_unlock_bus;
> -	} else {
> -		priv->adap.lock_bus = i2c_parent_lock_bus;
> -		priv->adap.trylock_bus = i2c_parent_trylock_bus;
> -		priv->adap.unlock_bus = i2c_parent_unlock_bus;
> -	}
> +	if (muxc->mux_locked)
> +		priv->adap.lock_ops = &i2c_mux_lock_ops;
> +	else
> +		priv->adap.lock_ops = &i2c_parent_lock_ops;
>  
>  	/* Sanity check on class */
>  	if (i2c_mux_parent_classes(parent) & class)
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index c1f60a345db7..616f67635734 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -427,6 +427,20 @@ struct i2c_algorithm {
>  };
>  
>  /**
> + * struct i2c_lock_operations - represent I2C locking operations
> + * @lock_bus: Get exclusive access to an I2C bus segment
> + * @trylock_bus: Try to get exclusive access to an I2C bus segment
> + * @unlock_bus: Release exclusive access to an I2C bus segment
> + *
> + * The main operations are wrapped by i2c_lock_bus and i2c_unlock_bus.
> + */
> +struct i2c_lock_operations {
> +	void (*lock_bus)(struct i2c_adapter *, unsigned int flags);
> +	int (*trylock_bus)(struct i2c_adapter *, unsigned int flags);
> +	void (*unlock_bus)(struct i2c_adapter *, unsigned int flags);
> +};
> +
> +/**
>   * struct i2c_timings - I2C timing information
>   * @bus_freq_hz: the bus frequency in Hz
>   * @scl_rise_ns: time SCL signal takes to rise in ns; t(r) in the I2C specification
> @@ -536,6 +550,7 @@ struct i2c_adapter {
>  	void *algo_data;
>  
>  	/* data fields that are valid for all devices	*/
> +	const struct i2c_lock_operations *lock_ops;
>  	struct rt_mutex bus_lock;
>  	struct rt_mutex mux_lock;
>  
> @@ -552,10 +567,6 @@ struct i2c_adapter {
>  
>  	struct i2c_bus_recovery_info *bus_recovery_info;
>  	const struct i2c_adapter_quirks *quirks;
> -
> -	void (*lock_bus)(struct i2c_adapter *, unsigned int flags);
> -	int (*trylock_bus)(struct i2c_adapter *, unsigned int flags);
> -	void (*unlock_bus)(struct i2c_adapter *, unsigned int flags);
>  };
>  #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
>  
> @@ -597,7 +608,7 @@ int i2c_for_each_dev(void *data, int (*fn)(struct device *, void *));
>  static inline void
>  i2c_lock_bus(struct i2c_adapter *adapter, unsigned int flags)
>  {
> -	adapter->lock_bus(adapter, flags);
> +	adapter->lock_ops->lock_bus(adapter, flags);
>  }
>  
>  /**
> @@ -611,7 +622,7 @@ i2c_lock_bus(struct i2c_adapter *adapter, unsigned int flags)
>  static inline int
>  i2c_trylock_bus(struct i2c_adapter *adapter, unsigned int flags)
>  {
> -	return adapter->trylock_bus(adapter, flags);
> +	return adapter->lock_ops->trylock_bus(adapter, flags);
>  }
>  
>  /**
> @@ -623,7 +634,7 @@ i2c_trylock_bus(struct i2c_adapter *adapter, unsigned int flags)
>  static inline void
>  i2c_unlock_bus(struct i2c_adapter *adapter, unsigned int flags)
>  {
> -	adapter->unlock_bus(adapter, flags);
> +	adapter->lock_ops->unlock_bus(adapter, flags);
>  }
>  
>  static inline void
> -- 
> 2.1.4
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

Re: [PATCH v2] i2c: move locking operations to their own struct Daniel Vetter <daniel@ffwll.ch> - 2016-08-28 18:10 +0200

csiph-web