All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Dan Carpenter <dan.carpenter@oracle.co>,
	linux-sparse@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: detecting misuse of of_get_property
Date: Mon, 28 Oct 2019 23:49:15 +0100	[thread overview]
Message-ID: <20191028224914.enpqjkcvbxyeexnl@desk.local> (raw)
In-Reply-To: <ec277c12-c608-6326-7723-be8cab4f524a@rasmusvillemoes.dk>

On Mon, Oct 28, 2019 at 08:32:42PM +0100, Rasmus Villemoes wrote:
> Hi,
> 
> I just spent some time trying to convert some so far PPC-only drivers to
> be more generic. One of the things I had to do was convert stuff like
> 
>   u32 *val = of_get_property(np, "bla", NULL);
>   do_stuff_with(*val);
> 
> with
> 
>   of_property_read_u32(np, "bla", &val);
>   do_stuff_with(val);
> 
> (error checking omitted for simplicity). The problem is that
> of_get_property() just returns void*. When the property is just a
> string, there's no problem interpreting that as a char*. But when the
> property is a number of array of numbers, I'd like some way to flag
> casting it to u32* as an error - if you cast it to a (pointer to integer
> type wider than char), it must be to a __be32*. Is there some way
> sparse/smatch could help find such cases?

If I understand you correctly, you would need a kind of 'soft'
bitwise pointer?
I guess it shouldn't be too hard to add a new flag which would
allow cast of bitwise pointers to pointers to char/void (see
at end of evaluate.c:evaluate_cast()).

Note: casts from bitwise pointer to void* are already allowed.

-- Luc

  reply	other threads:[~2019-10-28 22:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-28 19:32 detecting misuse of of_get_property Rasmus Villemoes
2019-10-28 22:49 ` Luc Van Oostenryck [this message]
2019-10-29  7:24   ` Rasmus Villemoes
2019-10-29 10:50 ` Dan Carpenter
2019-10-29 11:43   ` Rasmus Villemoes
2019-10-29 12:57     ` Dan Carpenter
2019-10-29 11:47   ` Luc Van Oostenryck
2019-10-29 12:55     ` Dan Carpenter
2019-10-29 13:37       ` Luc Van Oostenryck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191028224914.enpqjkcvbxyeexnl@desk.local \
    --to=luc.vanoostenryck@gmail.com \
    --cc=dan.carpenter@oracle.co \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.