Skip to content

i2c: Remove redundant driver field from the i2c_client struct

Lars-Peter Clausen alsa-devel dri-devel linux-i2c linux-media lkml 1 version Applied

Status from this message: Applied to for-next with great pleasure, thanks!

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest8 patches 9 repliesApplied

Patches in v1 Applied

#Subject and filesSizeRepliesApplied
1/8s5c73m3: Don't use i2c_client->driverdrivers/media/i2c/s5c73m3/s5c73m3-core.c+1 -11 reply
2/8exynos4-is: Don't use i2c_client->driverdrivers/media/platform/exynos4-is/media-dev.c+3 -32 replies
3/8core: Don't use i2c_client->driverdrivers/media/v4l2-core/tuner-core.c drivers/media/v4l2-core/v4l2-common.c include/media/v4l2-common.h+9 -92 replies
4/8drm: encoder_slave: Don't use i2c_client->driverdrivers/gpu/drm/drm_encoder_slave.c+4 -40 replies
5/8drm: nouveau: Don't use i2c_client->driverdrivers/gpu/drm/nouveau/core/subdev/therm/ic.c+2 -10 replies
6/8ALSA: ppc: keywest: Don't use i2c_client->driversound/ppc/keywest.c+2 -21 reply
7/8ASoC: imx-wm8962: Don't use i2c_client->driversound/soc/fsl/imx-wm8962.c+1 -11 reply
8/8i2c: Remove redundant 'driver' field from the i2c_client structdrivers/i2c/i2c-core.c drivers/i2c/i2c-smbus.c include/linux/i2c.h+18 -150 replies

Reviews trailers per patch

5 of 8 patches have a Reviewed-by or Acked-by.

PatchMark BrownSylwester NawrockiTakashi IwaiHans VerkuilMauro Carvalho Chehab
1/8A-b
2/8A-b A-b
3/8A-b A-b
4/8
5/8
6/8A-b
7/8A-b
8/8

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v1 thread

Cover letter [PATCH 0/8] i2c: Remove redundant driver field from the i2c_client struct

Hi,

This series removes the redundant driver field from the i2c_client struct. The field is redundant since the same pointer can be accessed through to_i2c_driver(client->dev.driver). The commit log suggests that the field has been around since forever (since before v2.6.12-rc2) and it looks as if it was simply forgotten to remove it during the conversion of the i2c framework to the generic device driver model.

Nevertheless there are a still a few users of the field around. This series first updates all users to use an alternative method of accessing the same data and then the last patch removes the driver field from the i2c_client struct.

Note that due to this changes on most architectures neither the code size nor the type of generated instructions will change. This is due to the fact that we aren't really interested in the pointer value itself, but rather want to dereference it to access one of the fields of the struct. offset_of() (and hence to_i2c_driver) works by subtracting a offset from the pointer, so the compiler can internally create the sum of these two offsets and use that to access the field.

E.g. on ARM the expression client->driver->command(...) generates

		...
		ldr     r3, [r0, #28]
		ldr     r3, [r3, #32]
		blx     r3
		...

and the expression to_i2c_driver(client->dev.driver)->command(...) generates

		...
		ldr     r3, [r0, #160]
    	ldr     r3, [r3, #-4]
    	blx     r3
		...

Other architectures will generate similar code.

The most common pattern is to use the i2c_driver to get to the device_driver struct embedded in it. The same struct can easily be accessed through the device struct embedded in the i2c_client struct. E.g. client->driver->driver.field can be replaced by client->dev.driver->field. Here again the generated code is almost identical and only the offsets differ.

E.g. on ARM the expression 'client->driver->driver.owner' generates

		ldr     r3, [r0, #28]
		ldr     r0, [r3, #44]

and 'client->dev.driver->owner' generates

		ldr     r3, [r0, #160]
		ldr     r0, [r3, #8]

The kernel overall code size is slightly reduced since the code that manages the driver field is removed and of course also the runtime memory footprint of the i2c_client struct is reduced.

- Lars

Lars-Peter Clausen (8):
[media] s5c73m3: Don't use i2c_client->driver
[media] exynos4-is: Don't use i2c_client->driver [media] core: Don't use i2c_client->driver
drm: encoder_slave: Don't use i2c_client->driver
drm: nouveau: Don't use i2c_client->driver
ALSA: ppc: keywest: Don't use i2c_client->driver
ASoC: imx-wm8962: Don't use i2c_client->driver
i2c: Remove redundant 'driver' field from the i2c_client struct

 drivers/gpu/drm/drm_encoder_slave.c            |  8 ++++----
 drivers/gpu/drm/nouveau/core/subdev/therm/ic.c |  3 ++-
 drivers/i2c/i2c-core.c                         | 21 ++++++++++++---------
 drivers/i2c/i2c-smbus.c                        | 10 ++++++----
 drivers/media/i2c/s5c73m3/s5c73m3-core.c       |  2 +-
 drivers/media/platform/exynos4-is/media-dev.c  |  6 +++---
 drivers/media/v4l2-core/tuner-core.c           |  6 +++---
 drivers/media/v4l2-core/v4l2-common.c          | 10 +++++-----
 include/linux/i2c.h                            |  2 --
 include/media/v4l2-common.h                    |  2 +-
 sound/ppc/keywest.c                            |  4 ++--
 sound/soc/fsl/imx-wm8962.c                     |  2 +-
 12 files changed, 40 insertions(+), 36 deletions(-)
Signature · 1 line
1.8.0