From f60301665ba9f75735d769c0bd778d5ffd42fb6b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 25 May 2019 14:12:00 -0600 Subject: [PATCH] fs/procfs/fs_procfs.c: procfs_initialize() is used only within fs/procfs/fs_procfs.c and, hence, should be marked 'static'. --- fs/procfs/fs_procfs.c | 55 +++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/fs/procfs/fs_procfs.c b/fs/procfs/fs_procfs.c index 121e61c299..4db3f51a29 100644 --- a/fs/procfs/fs_procfs.c +++ b/fs/procfs/fs_procfs.c @@ -188,13 +188,13 @@ static const struct procfs_entry_s g_procfs_entries[] = #ifdef CONFIG_FS_PROCFS_REGISTER static const uint8_t g_base_entrycount = sizeof(g_base_entries) / - sizeof(struct procfs_entry_s); + sizeof(struct procfs_entry_s); static FAR struct procfs_entry_s *g_procfs_entries; static uint8_t g_procfs_entrycount; #else static const uint8_t g_procfs_entrycount = sizeof(g_procfs_entries) / - sizeof(struct procfs_entry_s); + sizeof(struct procfs_entry_s); #endif /**************************************************************************** @@ -244,15 +244,9 @@ static int procfs_stat(FAR struct inode *mountpt, /* Initialization */ #ifdef CONFIG_FS_PROCFS_REGISTER -int procfs_initialize(void); -#else -# define procfs_initialize() +static int procfs_initialize(void); #endif -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Public Data ****************************************************************************/ @@ -616,12 +610,14 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, if (match(g_procfs_entries[x].pathpattern, relpath)) { - /* Match found! Call the handler's opendir routine. If successful, - * this opendir routine will create an entry derived from struct - * procfs_dir_priv_s as dir->u.procfs. + /* Match found! Call the handler's opendir routine. If + * successful, this opendir routine will create an entry + * derived from struct procfs_dir_priv_s as dir->u.procfs. */ - DEBUGASSERT(g_procfs_entries[x].ops && g_procfs_entries[x].ops->opendir); + DEBUGASSERT(g_procfs_entries[x].ops != NULL && + g_procfs_entries[x].ops->opendir != NULL); + ret = g_procfs_entries[x].ops->opendir(relpath, dir); if (ret == OK) @@ -639,14 +635,15 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, /* Test for a sub-string match (e.g. "ls /proc/fs") */ - else if (strncmp(g_procfs_entries[x].pathpattern, relpath, len) == 0) + else if (strncmp(g_procfs_entries[x].pathpattern, relpath, + len) == 0) { FAR struct procfs_level1_s *level1; /* Doing an intermediate directory search */ - /* The path refers to the top level directory. Allocate the level1 - * dirent structure. + /* The path refers to the top level directory. Allocate + * the level1 dirent structure. */ level1 = (FAR struct procfs_level1_s *) @@ -654,7 +651,8 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath, if (!level1) { - ferr("ERROR: Failed to allocate the level0 directory structure\n"); + ferr("ERROR: Failed to allocate the level0 directory " + "structure\n"); return -ENOMEM; } @@ -850,8 +848,8 @@ static int procfs_readdir(struct inode *mountpt, struct fs_dirent_s *dir) dir->fd_dir.d_type = DTYPE_DIRECTORY; snprintf(dir->fd_dir.d_name, NAME_MAX + 1, "%d", (int)pid); - /* Set up the next directory entry offset. NOTE that we could use the - * standard f_pos instead of our own private index. + /* Set up the next directory entry offset. NOTE that we could use + * the standard f_pos instead of our own private index. */ level0->base.index = index + 1; @@ -959,8 +957,8 @@ static int procfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir) * * Description: This implements a portion of the mount operation. This * function allocates and initializes the mountpoint private data and - * binds the blockdriver inode to the filesystem private data. The final - * binding of the private data (containing the blockdriver) to the + * binds the block driver inode to the filesystem private data. The final + * binding of the private data (containing the block driver) to the * mountpoint is performed by mount(). * ****************************************************************************/ @@ -968,9 +966,12 @@ static int procfs_rewinddir(struct inode *mountpt, struct fs_dirent_s *dir) static int procfs_bind(FAR struct inode *blkdriver, const void *data, void **handle) { +#ifdef CONFIG_FS_PROCFS_REGISTER /* Make sure that we are properly initialized */ procfs_initialize(); +#endif + return OK; } @@ -1063,7 +1064,8 @@ static int procfs_stat(struct inode *mountpt, const char *relpath, /* Test for an internal subdirectory stat */ - else if (strncmp(g_procfs_entries[x].pathpattern, relpath, len) == 0) + else if (strncmp(g_procfs_entries[x].pathpattern, relpath, + len) == 0) { /* It's an internal subdirectory */ @@ -1098,7 +1100,7 @@ int procfs_initialize(void) if (g_procfs_entries == NULL) { - /* No.. allocate a modifyable list of entries */ + /* No.. allocate a modifiable list of entries */ g_procfs_entries = (FAR struct procfs_entry_s *) kmm_malloc(sizeof(g_base_entries)); @@ -1168,7 +1170,9 @@ int procfs_register(FAR const struct procfs_entry_s *entry) newsize = newcount * sizeof(struct procfs_entry_s); sched_lock(); - newtable = (FAR struct procfs_entry_s *)kmm_realloc(g_procfs_entries, newsize); + newtable = (FAR struct procfs_entry_s *) + kmm_realloc(g_procfs_entries, newsize); + if (newtable == NULL) { /* Reallocation failed! */ @@ -1179,7 +1183,8 @@ int procfs_register(FAR const struct procfs_entry_s *entry) { /* Copy the new entry at the end of the reallocated table */ - memcpy(&newtable[g_procfs_entrycount], entry, sizeof(struct procfs_entry_s)); + memcpy(&newtable[g_procfs_entrycount], entry, + sizeof(struct procfs_entry_s)); /* Instantiate the reallocated table */