Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp111389ybi; Fri, 24 May 2019 00:44:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjtldGEJlf/dLY2UI1wVy1v+lccL9YaWAzyKUL15qqyDz94riDy4SqdgI7P8EGd68yBymt X-Received: by 2002:a63:441c:: with SMTP id r28mr23851470pga.255.1558683878111; Fri, 24 May 2019 00:44:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558683878; cv=none; d=google.com; s=arc-20160816; b=J8I8z94/J7tZkMFW4UtUjSuFQM8AIqNJ/HrgT1Ly2DtCLy61+Uamed22G8UgoUyWKV /zNWuY/KQToYFW8OaPPLIHCNytwo1ZZ7aJ2xjx0lopbg291yWxVO42A6Nm1XXL0nuglw uvH71UxaX6ecOk3U4cgBnI0tl77j+RLHascJBjeTx5HKwD9vYmAgtZXPB3ksJklWb7qv grl+CUh1qfnI8Lx1h8NjNkT4j6z0XmMmnApBNA8xM8hvIo7Rmw9m/lT1sGrjbzoPxZKw +Zq2gSWnWVV+N0Pbkjy/eTnt6mrQ0kmlICab7syQ60d5enmZgtNOFBCGwwilPFzKlz9Z kc/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=FRYxcsA8gB9FibohJrWOdhqpBp517njxkreby+OWZAA=; b=ISCxPEOwF4FCCu9zgM3o5yNZNxsFrfxKCzno+4ljhwcVmiCGInhjl0RmRgTp6AIj8i +4EKwqihevIEZdwQAGAv1l/kWkcbC7ev7jY7tnMyBTFP6NPQHErmtsYbOyTWAqNr+J2F hX4GAc3XWisp7zxEkfY7jj3vF5kAKai/fv4p6ZbfO2PzEaN4E9EWWveRFqwEvjua3G6t xX9VkczxRHDh1r+5EJjCve4Ie/WlfOZWdbRZjNDTEP9khFeKQjly/3aNOXlx9P9a1MAI TpW50EmBlHzzAQw9RiAUv7sL/e7sVoKp2NyQxaehkyOUyAP5WP2wzkv3C0mHuPzftLkp 5LJg== ARC-Authentication-Results: i=1; mx.google.com; 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 l15si2872141pfd.285.2019.05.24.00.44.18; Fri, 24 May 2019 00:44:38 -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; 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 S2389093AbfEXHlL (ORCPT + 99 others); Fri, 24 May 2019 03:41:11 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:40121 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388960AbfEXHlK (ORCPT ); Fri, 24 May 2019 03:41:10 -0400 Received: by mail-qk1-f193.google.com with SMTP id q197so6033838qke.7 for ; Fri, 24 May 2019 00:41:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FRYxcsA8gB9FibohJrWOdhqpBp517njxkreby+OWZAA=; b=a5i0hc5HW8w1Q7zIUP9Y7DPRDw4v8USDI6kD/nh9++tvffpz1+pgiRf+aAWJCuQAvc OIBY6KFziDqoUfqsDk4O8SSfsHBCc31jzc/FwSqDjEjnEaV6VHe3X5K5lB/RstOu6hL9 6CBlzXrLrpyAJoqlrkVjZ+tF9DJfKL63h6Lo156jmtIPoH1W+ZAGO0a2+cW4cXIytmOc h5wPK2oeuI+jYnGTp4IRuEob+oJ8PTmig6ExqmPWRNIwhP43sScFJPdsstJuTgX3J/Ts MWPDI6l//x6qkrE65S1luOK+DeMthJi+YNLJML9Es5IOQ8yzvWdi+9LneyLUVHQP9RJe kndg== X-Gm-Message-State: APjAAAW72Ci0vCiVaABYqUXR6hnFXMLStBV1GipmXcGSA1nvfm5IQhKT koA87j/MdXUDHVrfdJe81IhW9nhznkluqXATU5E= X-Received: by 2002:a37:3ce:: with SMTP id 197mr78391397qkd.14.1558683664367; Fri, 24 May 2019 00:41:04 -0700 (PDT) MIME-Version: 1.0 References: <20190523161532.122421-1-natechancellor@gmail.com> In-Reply-To: From: Arnd Bergmann Date: Fri, 24 May 2019 09:40:47 +0200 Message-ID: Subject: Re: [PATCH] misc: sgi-xp: Properly initialize buf in xpc_get_rsvd_page_pa To: Nick Desaulniers Cc: Nathan Chancellor , Cliff Whickman , Robin Holt , Greg Kroah-Hartman , LKML , clang-built-linux , Stephen Hines , Tony Luck , rja@sgi.com, Fenghua Yu Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 23, 2019 at 8:05 PM 'Nick Desaulniers' via Clang Built Linux wrote: > > On Thu, May 23, 2019 at 9:20 AM Nathan Chancellor > wrote: > > > > Clang warns: > > > > drivers/misc/sgi-xp/xpc_partition.c:73:14: warning: variable 'buf' is > > uninitialized when used within its own initialization [-Wuninitialized] > > void *buf = buf; > > ~~~ ^~~ > > 1 warning generated. > > > > Initialize it to NULL, which is more deterministic. > > > > Fixes: 279290294662 ("[IA64-SGI] cleanup the way XPC locates the reserved page") > > Link: https://github.com/ClangBuiltLinux/linux/issues/466 > > Suggested-by: Stephen Hines > > Signed-off-by: Nathan Chancellor > > From https://github.com/ClangBuiltLinux/linux/issues/466#issuecomment-488781917 > I tried to follow the rabbit hole, but eventually these void* get > converted to u64's and passed along to function that I have no idea > whether they handle the value `(u64)(void*)0` or not. Either way, > they definitely don't handle uninitialized values/UB. > > I was going to cc Robin who's already cc'ed, but looks like this code > was last touched 7-10 years ago. + Tony and Fenghua for ia64 since > sn_partition_reserved_page_pa is defined in > arch/ia64/include/asm/sn/sn_sal.h. > > In absence of consensus, I'll prefer NULL to uninitialized. > Reviewed-by: Nick Desaulniers > Thanks Nathan for following up on this. I also had to take a look, and I think I understand what's going on, and interestingly, the code is correct, both before and after your patch. It's described in this comment: /* * Returns the physical address of the partition's reserved page through * an iterative number of calls. * * On first call, 'cookie' and 'len' should be set to 0, and 'addr' * set to the nasid of the partition whose reserved page's address is * being sought. * On subsequent calls, pass the values, that were passed back on the * previous call. * * While the return status equals SALRET_MORE_PASSES, keep calling * this function after first copying 'len' bytes starting at 'addr' * into 'buf'. Once the return status equals SALRET_OK, 'addr' will * be the physical address of the partition's reserved page. If the * return status equals neither of these, an error as occurred. */ static inline s64 sn_partition_reserved_page_pa(u64 buf, u64 *cookie, u64 *addr, u64 *len) so *len is set to zero on the first call and tells the bios how many bytes are accessible at 'buf', and it does get updated by the BIOS to tell us how many bytes it needs, and then we allocate that and try again. With that explanation added, Reviewed-by: Arnd Bergmann