Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3730723imm; Mon, 11 Jun 2018 00:21:54 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKGAkNY8SqcSGkYuRw5BIyLXg5YokIK56ycKoYfzytnAEucZP9VoKoFmRVVzaRwr4Ha1FtJ X-Received: by 2002:a17:902:d68b:: with SMTP id v11-v6mr16992502ply.16.1528701714595; Mon, 11 Jun 2018 00:21:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528701714; cv=none; d=google.com; s=arc-20160816; b=KiUPDp5i/rjoMs/JcxFH7J/eQMSL6m4SP0UTEZRNJowJnOVp3332vGPWoX0KV2k+G5 uUeBKj2WN/owOfoMlaBwnOKaNw3kV+E4TYEnPfN46Ye6bZTjj+n2NwHy2giJLwvwuEH/ S4sKk+1zZsFOIfgmTMPJwJkanCMMbGkd8/Bd0cTUpFfpVPSi1bBmATF2QJshnrozHie2 pbbhSn3t1H8caFsw9yoA97LkckEVyjve2irgHW9X3EqAJv3lQMzrqoKaEjMO6E4FRRZz 99Anr0I5lH3Z/f4wUYiGz9/QVyPbBAcG6TxGI4W1hieT66rTS55+SAnPnrCeAU/b2hTm mKUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=JfDoswYpU1DbMVGc6dfyBxy80pqwdiLp52lbhnmarmg=; b=aQuDczCHgCpVnpZ7exRaMeRrxhak61jj5RXhsbN9VeZJPnI3XmAU+LIUAzJNGYBn1o 0mDrpCBl8scFvubaRG80BUWFjq2+c8/7VRZmfFKXv49zYreQzMs/6PyVBrtJESuoCVSc rQzPxvPPbgo8zx67KLyTYPVS500lYwLlc3yVcnkLkdtx/U2+FNpyXtaFU8OwRHWx21D+ EwlpmrIeJaflcth6fXlDdmwR3ph4hK2UO97WdSP55kn2om3BCaz4BBpMgFovy5MHE+vo wxW+DIEgJZC6/JQO7RAn6xldS0xzRI3C+OKHXj53/91be/Yoq8pTJgw5xfVRCqFFUZcq cxkg== 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 h8-v6si45802867pll.58.2018.06.11.00.21.40; Mon, 11 Jun 2018 00:21:54 -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 S1754114AbeFKHVT (ORCPT + 99 others); Mon, 11 Jun 2018 03:21:19 -0400 Received: from mx2.suse.de ([195.135.220.15]:36117 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754035AbeFKHVS (ORCPT ); Mon, 11 Jun 2018 03:21:18 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C055DADE3; Mon, 11 Jun 2018 07:21:16 +0000 (UTC) Date: Mon, 11 Jun 2018 09:21:16 +0200 From: Johannes Thumshirn To: Zhouyang Jia Cc: "James E.J. Bottomley" , "Martin K. Petersen" , Hannes Reinecke , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] pcmcia: add error handling for pcmcia_enable_device Message-ID: <20180611072116.vaz4xff4pd6qxtj7@linux-x5ow.site> References: <1528694152-31724-1-git-send-email-jiazhouyang09@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1528694152-31724-1-git-send-email-jiazhouyang09@gmail.com> User-Agent: NeoMutt/20170912 (1.9.0) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 11, 2018 at 01:15:50PM +0800, Zhouyang Jia wrote: > When pcmcia_enable_device fails, the lack of error-handling code may > cause unexpected results. > > This patch adds error-handling code after calling pcmcia_enable_device. > > Signed-off-by: Zhouyang Jia > --- > drivers/scsi/pcmcia/qlogic_stub.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > diff --git a/drivers/scsi/pcmcia/qlogic_stub.c b/drivers/scsi/pcmcia/qlogic_stub.c > index 0556054..9287d52 100644 > --- a/drivers/scsi/pcmcia/qlogic_stub.c > +++ b/drivers/scsi/pcmcia/qlogic_stub.c > @@ -254,8 +254,14 @@ static void qlogic_release(struct pcmcia_device *link) > static int qlogic_resume(struct pcmcia_device *link) > { > scsi_info_t *info = link->priv; > + int ret; > + > + ret = pcmcia_enable_device(link); > + if (ret) { > + pcmcia_disable_device(link); > + return -ENODEV; > + } pcmcia_enable_device() can fail for three reasons: 1) the socket is not present 2) the configuration is locked 3) setting the socket's power control fails In all three cases I think it's actually an error to call pcmcia_disable_device(). Imagine the following scenario: pcmcia_enable_device() failed because the device configuration is locked by another driver, then you call pcmcia_disable_device() which calls pcmcia_release_configuration(). pcmcia_release_configuration() checks if the device is locked, decrements the lock counter, clears the CONFIG_LOCKED bit in the PCMCIA config and sets the voltage to 0 without the first driver every noticing it. Byte, Johannes -- Johannes Thumshirn Storage jthumshirn@suse.de +49 911 74053 689 SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg GF: Felix Imend?rffer, Jane Smithard, Graham Norton HRB 21284 (AG N?rnberg) Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850