Return-Path: Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:64098 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232892AbhBOQFF (ORCPT ); Mon, 15 Feb 2021 11:05:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : content-transfer-encoding : in-reply-to : sender; s=pp1; bh=q3dqaSz5L4jeExQOxLDbUFVDJImzmwKduPLF8pr9tBQ=; b=e/8T467PoGKnHgmEaEfpwSHTQVylKSA/IDzo7AeTVT/yo8kWVHt4RfzGQZcO+hFyOl1N NKnR0czvtQwOWqJ3iK0QzYOxJG/hG+efEH9gZo4pSN/q7hbaoMgApoipyn9RHnhSkrI3 58LzkMM3h41a/g27UyuefT4CG5/oVi7zVIwSFL6kcjfle/J9oZeyCZQGQkD0onK6+vSr 9vVYVMbxNOWPZ6Hk9ZCc+S6S8hLKvxSXm2YQblcIyUAY2kyeKl7QrIPBJOF/0ZPf+A3X 3Ee+aQRZNM/zu8nPQJHRZIMN7z+ltgSX+NLK/0C/YCkYAqn2ToGZcrr06eRBbzi1Ohk3 qA== Date: Mon, 15 Feb 2021 17:04:09 +0100 From: Benjamin Block Subject: Re: False Positive return_cast check Message-ID: References: <20210215123625.GI2087@kadam> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20210215123625.GI2087@kadam> Sender: Benjamin Block List-ID: To: Dan Carpenter Cc: Mailing List linux-smatch On Mon, Feb 15, 2021 at 03:36:25PM +0300, Dan Carpenter wrote: > On Fri, Feb 12, 2021 at 01:42:54PM +0100, Benjamin Block wrote: > > Hello, > >=20 > > I hope this is the right avenue to report this. > >=20 > > I noticed yesterday that we get a false positive report from smatch for > > `pathmask_to_pos()` in `arch/s390/include/asm/cio.h`. When reviewing > > some code I got this error while using smatch: Forgot to mention that I am using smatch at commit 1490b5d272bc (heads/smatch-1.71). > >=20 > > CHECK /home/bblock/src/linux/drivers/s390/cio/device_pgid.c > > /home/bblock/src/linux/arch/s390/include/asm/cio.h:356 pathmask_to_po= s() warn: signedness bug returning '(-119)' > >=20 > > Which corresponds to this helper: > >=20 > > static inline u8 pathmask_to_pos(u8 mask) > > { > > return 8 - ffs(mask); > > } > >=20 >=20 > Could you add some debug code, like this: >=20 >=20 > #include "/path/to/smatch/check_debug.h" > static inline u8 pathmask_to_pos(u8 mask) > { > __smatch_bits(mask); > __smatch_implied(mask); > __smatch_implied(ffs(mask)); > return 8 - ffs(mask); > } >=20 > Then run: > /path/to/smatch/smatch_scripts/kchecker /home/bblock/src/linux/drivers/s3= 90/cio/device_pgid.c >=20 Sure, I got this: make[3]: Nothing to be done for 'drivers/s390/cio/device_pgid.o'. CHECK /home/bblock/src/linux/drivers/s390/cio/device_pgid.c /home/bblock/src/linux/arch/s390/include/asm/cio.h:358 pathmask_to_pos() = bit info 'mask': definitely set 0x0. possibly set 0xff. /home/bblock/src/linux/arch/s390/include/asm/cio.h:359 pathmask_to_pos() = implied: mask =3D '' /home/bblock/src/linux/arch/s390/include/asm/cio.h:360 pathmask_to_pos() = implied: ffs(mask) =3D '0-127' /home/bblock/src/linux/arch/s390/include/asm/cio.h:361 pathmask_to_pos() = warn: signedness bug returning '(-119)' (The long paths happen because I use out-of-tree builds with `O=3D/..`) --=20 Best Regards, Benjamin Block / Linux on IBM Z Kernel Development / IBM Sys= tems IBM Deutschland Research & Development GmbH / https://www.ibm.com/pri= vacy Vorsitz. AufsR.: Gregor Pillen / Gesch=E4ftsf=FChrung: Dirk = Wittkopp Sitz der Gesellschaft: B=F6blingen / Registergericht: AmtsG Stuttgart, HRB = 243294