Skip to content

Commit 460c52a

Browse files
niklas88Alexander Gordeev
authored andcommitted
s390/debug: Split private data alloc/free out of file operations
Split the allocation respectively freeing of file_private_info_t out of open() respectively close(). This will be used in a follow on change to access to debug views without going through the s390dbf filesystem. Reviewed-by: Halil Pasic <pasic@linux.ibm.com> Signed-off-by: Niklas Schnelle <schnelle@linux.ibm.com> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
1 parent 7832b30 commit 460c52a

1 file changed

Lines changed: 48 additions & 30 deletions

File tree

arch/s390/kernel/debug.c

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,42 @@ static ssize_t debug_input(struct file *file, const char __user *user_buf,
535535
return rc; /* number of input characters */
536536
}
537537

538+
static file_private_info_t *debug_file_private_alloc(debug_info_t *debug_info,
539+
struct debug_view *view)
540+
{
541+
debug_info_t *debug_info_snapshot;
542+
file_private_info_t *p_info;
543+
544+
/*
545+
* Make snapshot of current debug areas to get it consistent.
546+
* To copy all the areas is only needed, if we have a view which
547+
* formats the debug areas.
548+
*/
549+
if (!view->format_proc && !view->header_proc)
550+
debug_info_snapshot = debug_info_copy(debug_info, NO_AREAS);
551+
else
552+
debug_info_snapshot = debug_info_copy(debug_info, ALL_AREAS);
553+
554+
if (!debug_info_snapshot)
555+
return NULL;
556+
p_info = kmalloc(sizeof(file_private_info_t), GFP_KERNEL);
557+
if (!p_info) {
558+
debug_info_free(debug_info_snapshot);
559+
return NULL;
560+
}
561+
p_info->offset = 0;
562+
p_info->debug_info_snap = debug_info_snapshot;
563+
p_info->debug_info_org = debug_info;
564+
p_info->view = view;
565+
p_info->act_area = 0;
566+
p_info->act_page = 0;
567+
p_info->act_entry = DEBUG_PROLOG_ENTRY;
568+
p_info->act_entry_offset = 0;
569+
debug_info_get(debug_info);
570+
571+
return p_info;
572+
}
573+
538574
/*
539575
* debug_open:
540576
* - called for user open()
@@ -543,7 +579,7 @@ static ssize_t debug_input(struct file *file, const char __user *user_buf,
543579
*/
544580
static int debug_open(struct inode *inode, struct file *file)
545581
{
546-
debug_info_t *debug_info, *debug_info_snapshot;
582+
debug_info_t *debug_info;
547583
file_private_info_t *p_info;
548584
int i, rc = 0;
549585

@@ -561,42 +597,26 @@ static int debug_open(struct inode *inode, struct file *file)
561597
goto out;
562598

563599
found:
564-
565-
/* Make snapshot of current debug areas to get it consistent. */
566-
/* To copy all the areas is only needed, if we have a view which */
567-
/* formats the debug areas. */
568-
569-
if (!debug_info->views[i]->format_proc && !debug_info->views[i]->header_proc)
570-
debug_info_snapshot = debug_info_copy(debug_info, NO_AREAS);
571-
else
572-
debug_info_snapshot = debug_info_copy(debug_info, ALL_AREAS);
573-
574-
if (!debug_info_snapshot) {
575-
rc = -ENOMEM;
576-
goto out;
577-
}
578-
p_info = kmalloc(sizeof(file_private_info_t), GFP_KERNEL);
600+
p_info = debug_file_private_alloc(debug_info, debug_info->views[i]);
579601
if (!p_info) {
580-
debug_info_free(debug_info_snapshot);
581602
rc = -ENOMEM;
582603
goto out;
583604
}
584-
p_info->offset = 0;
585-
p_info->debug_info_snap = debug_info_snapshot;
586-
p_info->debug_info_org = debug_info;
587-
p_info->view = debug_info->views[i];
588-
p_info->act_area = 0;
589-
p_info->act_page = 0;
590-
p_info->act_entry = DEBUG_PROLOG_ENTRY;
591-
p_info->act_entry_offset = 0;
592605
file->private_data = p_info;
593-
debug_info_get(debug_info);
594606
nonseekable_open(inode, file);
595607
out:
596608
mutex_unlock(&debug_mutex);
597609
return rc;
598610
}
599611

612+
static void debug_file_private_free(file_private_info_t *p_info)
613+
{
614+
if (p_info->debug_info_snap)
615+
debug_info_free(p_info->debug_info_snap);
616+
debug_info_put(p_info->debug_info_org);
617+
kfree(p_info);
618+
}
619+
600620
/*
601621
* debug_close:
602622
* - called for user close()
@@ -607,10 +627,8 @@ static int debug_close(struct inode *inode, struct file *file)
607627
file_private_info_t *p_info;
608628

609629
p_info = (file_private_info_t *) file->private_data;
610-
if (p_info->debug_info_snap)
611-
debug_info_free(p_info->debug_info_snap);
612-
debug_info_put(p_info->debug_info_org);
613-
kfree(file->private_data);
630+
debug_file_private_free(p_info);
631+
file->private_data = NULL;
614632
return 0; /* success */
615633
}
616634

0 commit comments

Comments
 (0)