linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] activate context checking when context input and output values in __attribute__() are the same and different of zero
@ 2008-02-04 20:42 sylvain nahas
  2008-04-21 19:17 ` Josh Triplett
  0 siblings, 1 reply; 2+ messages in thread
From: sylvain nahas @ 2008-02-04 20:42 UTC (permalink / raw)
  To: linux-sparse

Hi,
the following patch activates context checking when context input and
output values are the same and different of zero in
__attribute__((context())), by making the parser generate a OP_CONTEXT
pseudo instruction.

Use case: specify that a function needs to be called in locked context.

Below is a sample case.
---
#define __needlock      __attribute__((context(lock,1,1)))
#define __acquire(x)	__context__(1)
#define __release(x)    __context__(-1)

static int __needlock test1(void)
{
	return 0;
}

static int __needlock test2(void)
{
	return test1(); /* OK */
}

static int test3(void)
{
        return test1(); /* should generate a warning */
}

int main(void)
{
	test1(); /* should generate a warning */
	test2(); /* should generate a warning */
	test3(); /* OK */
	__acquire();
	test1(); /* OK */
	__release();
	return -1;
}
---

I have used it on a relative big bunch of code and I believe it works well.
Thanks,

signed-off-by: Sylvain Nahas <sylvain.nahas@googlemailcom>
---
--- a/linearize.c
+++ b/linearize.c
@@ -1244,6 +1244,12 @@ static pseudo_t
linearize_call_expression(struct entrypoint *ep, struct expressi
                                out = 0;
                        }
                        context_diff = out - in;
+
+                       if( !context_diff && (in>0) ){
+                               check = 1;
+                               context_diff = in;
+                       }
+
                        if (check || context_diff) {
                                insn = alloc_instruction(OP_CONTEXT, 0);
                                insn->increment = context_diff;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] activate context checking when context input and output values in __attribute__() are the same and different of zero
  2008-02-04 20:42 [PATCH] activate context checking when context input and output values in __attribute__() are the same and different of zero sylvain nahas
@ 2008-04-21 19:17 ` Josh Triplett
  0 siblings, 0 replies; 2+ messages in thread
From: Josh Triplett @ 2008-04-21 19:17 UTC (permalink / raw)
  To: sylvain nahas; +Cc: linux-sparse

[-- Attachment #1: Type: text/plain, Size: 509 bytes --]

sylvain nahas wrote:
> the following patch activates context checking when context input and
> output values are the same and different of zero in
> __attribute__((context())), by making the parser generate a OP_CONTEXT
> pseudo instruction.
> 
> Use case: specify that a function needs to be called in locked context.

I have applied a patch from Johannes Berg which should also address this
problem.  Could you confirm that current Sparse from Git has the behavior
you want?

- Josh Triplett


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-04-21 19:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-04 20:42 [PATCH] activate context checking when context input and output values in __attribute__() are the same and different of zero sylvain nahas
2008-04-21 19:17 ` Josh Triplett

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).