Skip to content

Commit 7981593

Browse files
JoePerchesgregkh
authored andcommitted
mm: and drivers core: Convert hugetlb_report_node_meminfo to sysfs_emit
Convert the unbound sprintf in hugetlb_report_node_meminfo to use sysfs_emit_at so that no possible overrun of a PAGE_SIZE buf can occur. Signed-off-by: Joe Perches <[email protected]> Acked-by: Mike Kravetz <[email protected]> Link: https://lore.kernel.org/r/894b351b82da6013cde7f36ff4b5493cd0ec30d0.1600285923.git.joe@perches.com Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 948b3ed commit 7981593

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

drivers/base/node.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ static ssize_t node_read_meminfo(struct device *dev,
473473
HPAGE_PMD_NR)
474474
#endif
475475
);
476-
len += hugetlb_report_node_meminfo(nid, buf + len);
476+
len += hugetlb_report_node_meminfo(buf, len, nid);
477477
return len;
478478
}
479479

include/linux/hugetlb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct *vma,
129129
unsigned long start, unsigned long end,
130130
struct page *ref_page);
131131
void hugetlb_report_meminfo(struct seq_file *);
132-
int hugetlb_report_node_meminfo(int, char *);
132+
int hugetlb_report_node_meminfo(char *buf, int len, int nid);
133133
void hugetlb_show_meminfo(void);
134134
unsigned long hugetlb_total_pages(void);
135135
vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
@@ -245,7 +245,7 @@ static inline void hugetlb_report_meminfo(struct seq_file *m)
245245
{
246246
}
247247

248-
static inline int hugetlb_report_node_meminfo(int nid, char *buf)
248+
static inline int hugetlb_report_node_meminfo(char *buf, int len, int nid)
249249
{
250250
return 0;
251251
}

mm/hugetlb.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,18 +3582,20 @@ void hugetlb_report_meminfo(struct seq_file *m)
35823582
seq_printf(m, "Hugetlb: %8lu kB\n", total / 1024);
35833583
}
35843584

3585-
int hugetlb_report_node_meminfo(int nid, char *buf)
3585+
int hugetlb_report_node_meminfo(char *buf, int len, int nid)
35863586
{
35873587
struct hstate *h = &default_hstate;
3588+
35883589
if (!hugepages_supported())
35893590
return 0;
3590-
return sprintf(buf,
3591-
"Node %d HugePages_Total: %5u\n"
3592-
"Node %d HugePages_Free: %5u\n"
3593-
"Node %d HugePages_Surp: %5u\n",
3594-
nid, h->nr_huge_pages_node[nid],
3595-
nid, h->free_huge_pages_node[nid],
3596-
nid, h->surplus_huge_pages_node[nid]);
3591+
3592+
return sysfs_emit_at(buf, len,
3593+
"Node %d HugePages_Total: %5u\n"
3594+
"Node %d HugePages_Free: %5u\n"
3595+
"Node %d HugePages_Surp: %5u\n",
3596+
nid, h->nr_huge_pages_node[nid],
3597+
nid, h->free_huge_pages_node[nid],
3598+
nid, h->surplus_huge_pages_node[nid]);
35973599
}
35983600

35993601
void hugetlb_show_meminfo(void)

0 commit comments

Comments
 (0)