From patchwork Mon Jan 9 08:54:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 9504195 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1FD2560757 for ; Mon, 9 Jan 2017 08:55:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E82128462 for ; Mon, 9 Jan 2017 08:55:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 033902846E; Mon, 9 Jan 2017 08:55:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B274428462 for ; Mon, 9 Jan 2017 08:55:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757136AbdAIIzA (ORCPT ); Mon, 9 Jan 2017 03:55:00 -0500 Received: from mx2.suse.de ([195.135.220.15]:37091 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750933AbdAIIy7 (ORCPT ); Mon, 9 Jan 2017 03:54:59 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 11133AC97; Mon, 9 Jan 2017 08:54:58 +0000 (UTC) Date: Mon, 9 Jan 2017 09:54:52 +0100 From: Johannes Thumshirn To: Nicolas Iooss Cc: Anil Gurumurthy , Sudarsana Kalluru , "James E.J. Bottomley" , "Martin K. Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: Uninitialized variable in bfad_im_bsg_els_ct_request Message-ID: <20170109085452.GA3711@linux-x5ow.site> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Sun, Dec 18, 2016 at 09:44:27PM +0100, Nicolas Iooss wrote: > Hello, > > Currently on Linus master tree and in linux-next [1], > bfad_im_bsg_els_ct_request() code starts with the following code: > > int > bfad_im_bsg_els_ct_request(struct bsg_job *job) > { > /*...*/ > struct fc_bsg_request *bsg_request = bsg_request; > struct fc_bsg_reply *bsg_reply = job->reply; > uint32_t command_type = bsg_request->msgcode; > > The local variable "bsg_request" is initialized to itself (which would > usually mean it is uninitialized) but it is dereferenced in order to get > its "msgcode" field. As I am quite new to the kernel code and > dereferencing self-initialized local variables looks black magic to me, > could you please describe why this code is valid? > > It has recently been introduced by commit 01e0e15c8b3b ("scsi: don't use > fc_bsg_job::request and fc_bsg_job::reply directly"). > > Thanks, > Nicolas Iooss > > [1] > https://git.kernel.org/cgit/linux/kernel/git/next/linux-next.git/tree/drivers/scsi/bfa/bfad_bsg.c?id=06548160dfecd1983ffd9d6795242a5cda095da5#n3356 Yes this is wrong. bsg_request should point to job->request: I'll send out an official patch soon, thanks for the report. Johannes diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c index a9a0016..b2e8c0d 100644 --- a/drivers/scsi/bfa/bfad_bsg.c +++ b/drivers/scsi/bfa/bfad_bsg.c @@ -3363,7 +3363,7 @@ struct bfad_buf_info * struct bfad_fcxp *drv_fcxp; struct bfa_fcs_lport_s *fcs_port; struct bfa_fcs_rport_s *fcs_rport; - struct fc_bsg_request *bsg_request = bsg_request; + struct fc_bsg_request *bsg_request = job->request; struct fc_bsg_reply *bsg_reply = job->reply; uint32_t command_type = bsg_request->msgcode; unsigned long flags;