From 23b969b777238d45d0e061f25dd93fbfaf5ee7bc Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 14 Apr 2025 08:03:23 +0200 Subject: pkg/declextract: add open fileops callback to interface list Add open callback if there are no other unique callbacks. This happens for e.g. seq files which only have unique open, while read is a common seq_read callback. --- pkg/declextract/fileops.go | 6 +++++- pkg/declextract/typing.go | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'pkg') diff --git a/pkg/declextract/fileops.go b/pkg/declextract/fileops.go index 387db4f63..3a82d13c2 100644 --- a/pkg/declextract/fileops.go +++ b/pkg/declextract/fileops.go @@ -23,10 +23,14 @@ func (ctx *context) serializeFileOps() { for _, fops := range ctx.FileOps { files := fopsToFiles[fops] canGenerate := Tristate(len(files) != 0) - for _, op := range []*Function{fops.read, fops.write, fops.mmap} { + for _, op := range []*Function{fops.open, fops.read, fops.write, fops.mmap} { if op == nil { continue } + if op == fops.open && (uniqueFuncs[fops.read] == 1 || uniqueFuncs[fops.write] == 1 || + uniqueFuncs[fops.mmap] == 1 || uniqueFuncs[fops.ioctl] == 1) { + continue + } ctx.noteInterface(&Interface{ Type: IfaceFileop, Name: op.Name, diff --git a/pkg/declextract/typing.go b/pkg/declextract/typing.go index 04a11bbc7..31ee31d5d 100644 --- a/pkg/declextract/typing.go +++ b/pkg/declextract/typing.go @@ -49,6 +49,11 @@ import ( // we can consider it as unused. // - Detect common patterns for "must be 0" or "must be const" arguments, e.g.: // if (flags != 0) return -EINVAL; +// - Capture taking address of functions in functions. +// If code takes a function address, the target function most likely needs to be accounted +// in LOC/complexity/coverage analysis (effectively called). We won't see this function +// to be called via a function pointer later, or it may be passed to a very common function +// that we won't analyze (e.g. single_open(..., show_callback, ...)). var ( // Refines types based on data flows... -- cgit mrf-deployment