Skip to content

Commit 96fb1b6

Browse files
commodoJonathan Cameron
authored andcommitted
iio: core: move debugfs data on the private iio dev info
This change moves all iio_dev debugfs fields to the iio_dev_priv object. It's not the biggest advantage yet (to the whole thing of abstractization) but it's a start. The iio_get_debugfs_dentry() function (which is moved in industrialio-core.c) needs to also be guarded against the CONFIG_DEBUG_FS symbol, when it isn't defined. We do want to keep the inline definition in the iio.h header, so that the compiler can better infer when to compile out debugfs code that is related to the IIO debugfs directory. Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 09673d5 commit 96fb1b6

3 files changed

Lines changed: 44 additions & 25 deletions

File tree

‎drivers/iio/industrialio-core.c‎

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,19 @@ static const char * const iio_chan_info_postfix[] = {
165165
[IIO_CHAN_INFO_THERMOCOUPLE_TYPE] = "thermocouple_type",
166166
};
167167

168+
#if defined(CONFIG_DEBUG_FS)
169+
/**
170+
* There's also a CONFIG_DEBUG_FS guard in include/linux/iio/iio.h for
171+
* iio_get_debugfs_dentry() to make it inline if CONFIG_DEBUG_FS is undefined
172+
*/
173+
struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
174+
{
175+
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
176+
return iio_dev_opaque->debugfs_dentry;
177+
}
178+
EXPORT_SYMBOL_GPL(iio_get_debugfs_dentry);
179+
#endif
180+
168181
/**
169182
* iio_find_channel_from_si() - get channel from its scan index
170183
* @indio_dev: device
@@ -308,35 +321,37 @@ static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf,
308321
size_t count, loff_t *ppos)
309322
{
310323
struct iio_dev *indio_dev = file->private_data;
324+
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
311325
unsigned val = 0;
312326
int ret;
313327

314328
if (*ppos > 0)
315329
return simple_read_from_buffer(userbuf, count, ppos,
316-
indio_dev->read_buf,
317-
indio_dev->read_buf_len);
330+
iio_dev_opaque->read_buf,
331+
iio_dev_opaque->read_buf_len);
318332

319333
ret = indio_dev->info->debugfs_reg_access(indio_dev,
320-
indio_dev->cached_reg_addr,
334+
iio_dev_opaque->cached_reg_addr,
321335
0, &val);
322336
if (ret) {
323337
dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__);
324338
return ret;
325339
}
326340

327-
indio_dev->read_buf_len = snprintf(indio_dev->read_buf,
328-
sizeof(indio_dev->read_buf),
329-
"0x%X\n", val);
341+
iio_dev_opaque->read_buf_len = snprintf(iio_dev_opaque->read_buf,
342+
sizeof(iio_dev_opaque->read_buf),
343+
"0x%X\n", val);
330344

331345
return simple_read_from_buffer(userbuf, count, ppos,
332-
indio_dev->read_buf,
333-
indio_dev->read_buf_len);
346+
iio_dev_opaque->read_buf,
347+
iio_dev_opaque->read_buf_len);
334348
}
335349

336350
static ssize_t iio_debugfs_write_reg(struct file *file,
337351
const char __user *userbuf, size_t count, loff_t *ppos)
338352
{
339353
struct iio_dev *indio_dev = file->private_data;
354+
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
340355
unsigned reg, val;
341356
char buf[80];
342357
int ret;
@@ -351,10 +366,10 @@ static ssize_t iio_debugfs_write_reg(struct file *file,
351366

352367
switch (ret) {
353368
case 1:
354-
indio_dev->cached_reg_addr = reg;
369+
iio_dev_opaque->cached_reg_addr = reg;
355370
break;
356371
case 2:
357-
indio_dev->cached_reg_addr = reg;
372+
iio_dev_opaque->cached_reg_addr = reg;
358373
ret = indio_dev->info->debugfs_reg_access(indio_dev, reg,
359374
val, NULL);
360375
if (ret) {
@@ -378,23 +393,28 @@ static const struct file_operations iio_debugfs_reg_fops = {
378393

379394
static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
380395
{
381-
debugfs_remove_recursive(indio_dev->debugfs_dentry);
396+
struct iio_dev_opaque *iio_dev_opaque = to_iio_dev_opaque(indio_dev);
397+
debugfs_remove_recursive(iio_dev_opaque->debugfs_dentry);
382398
}
383399

384400
static void iio_device_register_debugfs(struct iio_dev *indio_dev)
385401
{
402+
struct iio_dev_opaque *iio_dev_opaque;
403+
386404
if (indio_dev->info->debugfs_reg_access == NULL)
387405
return;
388406

389407
if (!iio_debugfs_dentry)
390408
return;
391409

392-
indio_dev->debugfs_dentry =
410+
iio_dev_opaque = to_iio_dev_opaque(indio_dev);
411+
412+
iio_dev_opaque->debugfs_dentry =
393413
debugfs_create_dir(dev_name(&indio_dev->dev),
394414
iio_debugfs_dentry);
395415

396416
debugfs_create_file("direct_reg_access", 0644,
397-
indio_dev->debugfs_dentry, indio_dev,
417+
iio_dev_opaque->debugfs_dentry, indio_dev,
398418
&iio_debugfs_reg_fops);
399419
}
400420
#else

‎include/linux/iio/iio-opaque.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@
66
/**
77
* struct iio_dev_opaque - industrial I/O device opaque information
88
* @indio_dev: public industrial I/O device information
9+
* @debugfs_dentry: device specific debugfs dentry
10+
* @cached_reg_addr: cached register address for debugfs reads
11+
* @read_buf: read buffer to be used for the initial reg read
12+
* @read_buf_len: data length in @read_buf
913
*/
1014
struct iio_dev_opaque {
1115
struct iio_dev indio_dev;
16+
#if defined(CONFIG_DEBUG_FS)
17+
struct dentry *debugfs_dentry;
18+
unsigned cached_reg_addr;
19+
char read_buf[20];
20+
unsigned int read_buf_len;
21+
#endif
1222
};
1323

1424
#define to_iio_dev_opaque(indio_dev) \

‎include/linux/iio/iio.h‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,6 @@ struct iio_buffer_setup_ops {
520520
* @groups: [INTERN] attribute groups
521521
* @groupcounter: [INTERN] index of next attribute group
522522
* @flags: [INTERN] file ops related flags including busy flag.
523-
* @debugfs_dentry: [INTERN] device specific debugfs dentry.
524-
* @cached_reg_addr: [INTERN] cached register address for debugfs reads.
525523
* @priv: [DRIVER] reference to driver's private information
526524
* **MUST** be accessed **ONLY** via iio_priv() helper
527525
*/
@@ -567,12 +565,6 @@ struct iio_dev {
567565
int groupcounter;
568566

569567
unsigned long flags;
570-
#if defined(CONFIG_DEBUG_FS)
571-
struct dentry *debugfs_dentry;
572-
unsigned cached_reg_addr;
573-
char read_buf[20];
574-
unsigned int read_buf_len;
575-
#endif
576568
void *priv;
577569
};
578570

@@ -733,10 +725,7 @@ static inline bool iio_buffer_enabled(struct iio_dev *indio_dev)
733725
* @indio_dev: IIO device structure for device
734726
**/
735727
#if defined(CONFIG_DEBUG_FS)
736-
static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
737-
{
738-
return indio_dev->debugfs_dentry;
739-
}
728+
struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev);
740729
#else
741730
static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
742731
{

0 commit comments

Comments
 (0)