Skip to contentSkip to conversation

ASoC: Remove 'const' from the device_node pointers

PATCH Mark Brown 2 participants 3 messages Nov 25, 2014

lore
Share & tools
lore

Mark Brown

author
#0 lore raw
Quoted 10 lines · Jean-Francois Moine

As Russell King's explained it, there should not be pointers to struct device_node:

"struct device_node is a ref-counted structure. That means if you
store a reference to it, you should "get" it, and you should "put" it once you've done. The act of "put"ing the pointed-to structure involves writing to that structure, so it is totally unappropriate to store a device_node structure as a const pointer. It forces you to have to cast it back to a non-const pointer at various points in time to use various OF function calls."

So, we're not holding references here (we're just doing comparisons, the references need to be owned before we get into the core) and I'm not seeing anything here removing casts?

#1 lore raw
Quoted 12 lines · Mark Brown
Quoted 10 lines · Jean-Francois Moine

As Russell King's explained it, there should not be pointers to struct device_node:

"struct device_node is a ref-counted structure. That means if you
store a reference to it, you should "get" it, and you should "put" it once you've done. The act of "put"ing the pointed-to structure involves writing to that structure, so it is totally unappropriate to store a device_node structure as a const pointer. It forces you to have to cast it back to a non-const pointer at various points in time to use various OF function calls."

Quoted 2 lines

So, we're not holding references here (we're just doing comparisons, the references need to be owned before we get into the core)

The core itself will only do the comparisons and it is the board drivers responsibility to get and put the references. Making the pointers non const allows the board driver to use them to put the reference once the card has been unregistered rather than having to keep a separate set of pointers around. This should probably be mentioned in the commit message though.

Quoted 1 line

I'm not seeing anything here removing casts?

This patch used to be part of a two part series where the second patch removed the casts. This patch as already been applied though.

author
#2 lore raw
Quoted 9 lines · Lars-Peter Clausen
Quoted 2 lines · Mark Brown

So, we're not holding references here (we're just doing comparisons, the references need to be owned before we get into the core)

The core itself will only do the comparisons and it is the board drivers responsibility to get and put the references. Making the pointers non const allows the board driver to use them to put the reference once the card has been unregistered rather than having to keep a separate set of pointers

Wouldn't it be even better to have managed OF references and not need to explicitly dereference at all? Otherwise every time something uses managed resources for the card or component we've got a (marginal admittedly) reference management bug.

Quoted 1 line

around. This should probably be mentioned in the commit message though.

Yes, it really should - this is really what I'm getting at here since I'm frequently having to push back on difficult to understand changes here.

Quoted 4 lines
Quoted 1 line

I'm not seeing anything here removing casts?

This patch used to be part of a two part series where the second patch removed the casts. This patch as already been applied though.

We don't have warnings at the minute...