Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: dsa: b53: Use a macro to define I/O operations

Instead of repeating the same pattern: acquire mutex, read/write,
release mutex, define a macro: b53_build_op() which takes the type
(read|write), I/O size, and value (scalar or pointer). This helps with
fixing bugs that could exist (e.g: missing barrier, lock etc.).

Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Florian Fainelli and committed by
David S. Miller
5345862e e85ec74a

+21 -110
+21 -110
drivers/net/dsa/b53/b53_priv.h
··· 199 199 dsa_unregister_switch(dev->ds); 200 200 } 201 201 202 - static inline int b53_read8(struct b53_device *dev, u8 page, u8 reg, u8 *val) 203 - { 204 - int ret; 205 - 206 - mutex_lock(&dev->reg_mutex); 207 - ret = dev->ops->read8(dev, page, reg, val); 208 - mutex_unlock(&dev->reg_mutex); 209 - 210 - return ret; 202 + #define b53_build_op(type_op_size, val_type) \ 203 + static inline int b53_##type_op_size(struct b53_device *dev, u8 page, \ 204 + u8 reg, val_type val) \ 205 + { \ 206 + int ret; \ 207 + \ 208 + mutex_lock(&dev->reg_mutex); \ 209 + ret = dev->ops->type_op_size(dev, page, reg, val); \ 210 + mutex_unlock(&dev->reg_mutex); \ 211 + \ 212 + return ret; \ 211 213 } 212 214 213 - static inline int b53_read16(struct b53_device *dev, u8 page, u8 reg, u16 *val) 214 - { 215 - int ret; 215 + b53_build_op(read8, u8 *); 216 + b53_build_op(read16, u16 *); 217 + b53_build_op(read32, u32 *); 218 + b53_build_op(read48, u64 *); 219 + b53_build_op(read64, u64 *); 216 220 217 - mutex_lock(&dev->reg_mutex); 218 - ret = dev->ops->read16(dev, page, reg, val); 219 - mutex_unlock(&dev->reg_mutex); 220 - 221 - return ret; 222 - } 223 - 224 - static inline int b53_read32(struct b53_device *dev, u8 page, u8 reg, u32 *val) 225 - { 226 - int ret; 227 - 228 - mutex_lock(&dev->reg_mutex); 229 - ret = dev->ops->read32(dev, page, reg, val); 230 - mutex_unlock(&dev->reg_mutex); 231 - 232 - return ret; 233 - } 234 - 235 - static inline int b53_read48(struct b53_device *dev, u8 page, u8 reg, u64 *val) 236 - { 237 - int ret; 238 - 239 - mutex_lock(&dev->reg_mutex); 240 - ret = dev->ops->read48(dev, page, reg, val); 241 - mutex_unlock(&dev->reg_mutex); 242 - 243 - return ret; 244 - } 245 - 246 - static inline int b53_read64(struct b53_device *dev, u8 page, u8 reg, u64 *val) 247 - { 248 - int ret; 249 - 250 - mutex_lock(&dev->reg_mutex); 251 - ret = dev->ops->read64(dev, page, reg, val); 252 - mutex_unlock(&dev->reg_mutex); 253 - 254 - return ret; 255 - } 256 - 257 - static inline int b53_write8(struct b53_device *dev, u8 page, u8 reg, u8 value) 258 - { 259 - int ret; 260 - 261 - mutex_lock(&dev->reg_mutex); 262 - ret = dev->ops->write8(dev, page, reg, value); 263 - mutex_unlock(&dev->reg_mutex); 264 - 265 - return ret; 266 - } 267 - 268 - static inline int b53_write16(struct b53_device *dev, u8 page, u8 reg, 269 - u16 value) 270 - { 271 - int ret; 272 - 273 - mutex_lock(&dev->reg_mutex); 274 - ret = dev->ops->write16(dev, page, reg, value); 275 - mutex_unlock(&dev->reg_mutex); 276 - 277 - return ret; 278 - } 279 - 280 - static inline int b53_write32(struct b53_device *dev, u8 page, u8 reg, 281 - u32 value) 282 - { 283 - int ret; 284 - 285 - mutex_lock(&dev->reg_mutex); 286 - ret = dev->ops->write32(dev, page, reg, value); 287 - mutex_unlock(&dev->reg_mutex); 288 - 289 - return ret; 290 - } 291 - 292 - static inline int b53_write48(struct b53_device *dev, u8 page, u8 reg, 293 - u64 value) 294 - { 295 - int ret; 296 - 297 - mutex_lock(&dev->reg_mutex); 298 - ret = dev->ops->write48(dev, page, reg, value); 299 - mutex_unlock(&dev->reg_mutex); 300 - 301 - return ret; 302 - } 303 - 304 - static inline int b53_write64(struct b53_device *dev, u8 page, u8 reg, 305 - u64 value) 306 - { 307 - int ret; 308 - 309 - mutex_lock(&dev->reg_mutex); 310 - ret = dev->ops->write64(dev, page, reg, value); 311 - mutex_unlock(&dev->reg_mutex); 312 - 313 - return ret; 314 - } 221 + b53_build_op(write8, u8); 222 + b53_build_op(write16, u16); 223 + b53_build_op(write32, u32); 224 + b53_build_op(write48, u64); 225 + b53_build_op(write64, u64); 315 226 316 227 struct b53_arl_entry { 317 228 u8 port;