Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4032588ybg; Tue, 29 Oct 2019 00:48:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzc8+3kK/b/J9CDoaJNVDt1V8dFI+4bh+nLNnUh0vA81nx+NY0yh6NZS2XIV9EiM0fOagRO X-Received: by 2002:aa7:d704:: with SMTP id t4mr11765725edq.23.1572335291675; Tue, 29 Oct 2019 00:48:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572335291; cv=none; d=google.com; s=arc-20160816; b=SqM/ZR+EydD+AmfW6t1JMZwLuymlsLu7v0y3haXx0bZjQsj41ceHemslS6XDVoN5hj Lh1IW7w0tsosgoy0GoNCK4LcIyoC3mv5LkRoHo0M/LXUP3s/GxjXUq8sDwYlkYA/tfXx R5ZKSVtclojLK9ae72tUY18daAB31zbCD8mczGPG9ka3tUKAIQD8rEOnL9swisZRNlNV JBZQWpo8LzKUNSrhmZpOFscPxXBIsaWM9bl2GMLJXO//DkxBTDia/m7CgHt2pgkF4oAl Jagz3CZ8ekxLZ1uy2anWiQPEQMB0/upQIdXTBnyx42IbmqRYiiMnXbGrp9aM1lTW2PA8 3HDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=SoFQNKQ4Qa81yrqKCpibxDMBO3sAN1LEi2FGE9F/8RA=; b=oykqwIY+nJiUqOPzuVbaB6+hOtDhyzEkQdiPD2JR6qCOheJI/mWIVzn12s0y+Qx0hY F4hk3InfigDEHVZJ23zHYH5GP5Oa6VQlimmUtpRx2kbsbgdWQSqQbOzD30zcfbUuXCz8 BSlKkh79n+gBj9FbOUA8tgDU+8BVjUEuPLt+DE/UmdCMnra7EaAzlklUF2CGDxouNghv oPsRVtkj5IbCDcz0+zrQm3Uoe8YRwZwUIoed9QEMC5nVQkkMRVAFulGtCyCtT5B3HWfv H9YzHuGEVEhT1jNgNPXz3SpcMaph8mO7h/Yqx6JRfLD5dH9c6TIrYLqh7LTReRzlQEuI qt4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b="Hy0//0hO"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x28si747573edd.427.2019.10.29.00.47.48; Tue, 29 Oct 2019 00:48:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b="Hy0//0hO"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726691AbfJ2HYi (ORCPT + 99 others); Tue, 29 Oct 2019 03:24:38 -0400 Received: from mail-lj1-f176.google.com ([209.85.208.176]:43461 "EHLO mail-lj1-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726047AbfJ2HYh (ORCPT ); Tue, 29 Oct 2019 03:24:37 -0400 Received: by mail-lj1-f176.google.com with SMTP id s4so13183993ljj.10 for ; Tue, 29 Oct 2019 00:24:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=SoFQNKQ4Qa81yrqKCpibxDMBO3sAN1LEi2FGE9F/8RA=; b=Hy0//0hOS03mKb68HU9qDOg02jeHGzftxkWxOIgCuOU7CKTJ+k6iUZX7gjKOSvGQPl 4BICrmSElIBBlJfP3hi6Yo0Otz+bH5RNw0pVZLArmHAfxPetqDt+zD9HpnTKyeckCM+D g8xjzcLF853wbCU3oVitJzkWqZdiNvQxj+RoY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=SoFQNKQ4Qa81yrqKCpibxDMBO3sAN1LEi2FGE9F/8RA=; b=d6o0DrI7gJKLk5aWlJ2Zde4n+lxFFUHhrdtkpAhngcdVZOlrB/bRLsrwprH6eN/FSJ O4gHLrkFRoqrJhjU3bG8FBrwg8INjVMI7KrLT+u22/hYnexvw+CXV4WQltzVJWIeMbZV HyYD+FuBd1sYzWADvpsMJ9mnkWUarrmPygQvkC1l5R0jvbYGitPNpeH1zf92VGOEiF19 O1yicS0Kyv/qd9Xq970pPy4dBAvOfwHyf9Rp1lraezeQQ8aLI5vu6Nx8H22bUnkzxRyF lXyhI8E00/YoKrKJkhQQnmVGy+SIVdyEIs49r/t1Cl1MPTsFSbVeZbfCtZ1fXTyBCEWU 47jw== X-Gm-Message-State: APjAAAU+rsGmxywjV/xuJ5RhAMoxxhBu6YfQrruTLyrlZGeiA0CkHcph gnmMGMA9ylCMe5CCico10HYYeqlyLGv9suE9 X-Received: by 2002:a2e:b0c9:: with SMTP id g9mr1293910ljl.95.1572333873850; Tue, 29 Oct 2019 00:24:33 -0700 (PDT) Received: from [172.16.11.28] ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id p88sm9377100ljp.13.2019.10.29.00.24.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Oct 2019 00:24:33 -0700 (PDT) Subject: Re: detecting misuse of of_get_property To: Luc Van Oostenryck Cc: Dan Carpenter , linux-sparse@vger.kernel.org, LKML References: <20191028224914.enpqjkcvbxyeexnl@desk.local> From: Rasmus Villemoes Message-ID: <2dcd6ac3-8a01-a11c-3532-5a8eb83ccdf5@rasmusvillemoes.dk> Date: Tue, 29 Oct 2019 08:24:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191028224914.enpqjkcvbxyeexnl@desk.local> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28/10/2019 23.49, Luc Van Oostenryck wrote: > 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? Yes, that's a very good way of putting it. > 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()). Hm, yeah, but it should also allow casting to __be32* , but not u32* or __le32* (though somebody must have gone out of their way to introduce a bug in the latter case). Don't spend too much time on it, I was just wondering if there was an easy (maybe already existing) way. Thanks, Rasmus