Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751481AbcDNTgZ (ORCPT ); Thu, 14 Apr 2016 15:36:25 -0400 Received: from SMTP.ANDREW.CMU.EDU ([128.2.105.203]:43977 "EHLO smtp.andrew.cmu.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750922AbcDNTgY (ORCPT ); Thu, 14 Apr 2016 15:36:24 -0400 Date: Thu, 14 Apr 2016 15:36:14 -0400 From: "Gabriel L. Somlo" To: Dan Carpenter Cc: "Michael S. Tsirkin" , qemu-devel@nongnu.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [patch] firmware: qemu_fw_cfg.c: potential unintialized variable Message-ID: <20160414193614.GE7821@HEDWIG.INI.CMU.EDU> References: <20160414093337.GD16549@mwanda> <20160414184005.GC7821@HEDWIG.INI.CMU.EDU> <20160414191253.GH4247@mwanda> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160414191253.GH4247@mwanda> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.5.24 (2015-08-30) X-PMX-Version: 6.3.0.2556906, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2016.4.14.192416 X-SMTP-Spam-Clean: 8% ( MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODYTEXTP_SIZE_3000_LESS 0, BODY_SIZE_1900_1999 0, BODY_SIZE_2000_LESS 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, DATE_TZ_NA 0, FROM_EDU_TLD 0, NO_CTA_URI_FOUND 0, NO_URI_FOUND 0, NO_URI_HTTPS 0, REFERENCES 0, __BOUNCE_CHALLENGE_SUBJ 0, __BOUNCE_NDR_SUBJ_EXEMPT 0, __CD 0, __CT 0, __CT_TEXT_PLAIN 0, __FORWARDED_MSG 0, __HAS_FROM 0, __HAS_MSGID 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MIME_VERSION 0, __MULTIPLE_RCPTS_CC_X2 0, __PHISH_SPEAR_STRUCTURE_1 0, __REFERENCES 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __SUBJ_ALPHA_NEGATE 0, __TO_MALFORMED_2 0, __USER_AGENT 0) X-SMTP-Spam-Score: 8% Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1899 Lines: 49 On Thu, Apr 14, 2016 at 10:12:53PM +0300, Dan Carpenter wrote: > On Thu, Apr 14, 2016 at 02:40:06PM -0400, Gabriel L. Somlo wrote: > > On Thu, Apr 14, 2016 at 12:33:37PM +0300, Dan Carpenter wrote: > > > It acpi_acquire_global_lock() return AE_NOT_CONFIGURED then "glk" isn't > > ^ ^ > > If returns > > > > > initialized, which, if you got very unlucky, could cause a bug. > > > > > > In principle I'm OK with being cautious and initializing local > > variables just in case, but I'm curious: > > > > acpi_acquire_global_lock() (and its friend, acpi_release_global_lock()) > > are both wrapped inside the same macro -- ACPI_HW_DEPENDENT_RETURN_STATUS > > -- which either makes them both do something useful, or makes them both > > no-ops returning a hardcoded AE_NOT_CONFIGURED. > > > > So what else do you think could be a way to get very unlucky ? > > If "glk" happened to to equal acpi_gbl_global_lock_handle by chance > then we would release it without acquiring it first. Actually I could > initialize it to zero and that would be better, no? No, because acpi_release_global_lock() would also be a hard-coded "return AE_NOT_CONFIGURED" by the same macro which also hard-coded acpi_acquire_global_lock() to be "return AE_NOT_CONFIGURED" in the first place. See include/acpi/acpixf.h, search for the two occurrences of "#define ACPI_HW_DEPENDENT_RETURN_STATUS" and then for: "global_lock" further down in the file. Whether both (or neither) of lock/unlock are for real or just hardcoded to return AE_NOT_CONFIGURED depends on ACPI_REDUCED_HARDWARE, which I assume is also set when there's *no* ACPI hardware at all. But I don't believe it's possible for "unlock" to do anything at all if "lock" was hardcoded to simply return AE_NOT_CONFIGURED. Then again, it's possible I'm still missing something :) Thanks, --Gabe