From patchwork Thu Feb 8 09:36:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fedor Pchelkin X-Patchwork-Id: 198256 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp49658dyd; Thu, 8 Feb 2024 01:37:47 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVIPnvieAOOxlEuy1mg7xQWTSyPMn+zJPFKhWM1dT6fp2mQrgihzxZYDtQLKRbiczoV4eeuAPV9aEi0Aiyd6S/2eab0kA== X-Google-Smtp-Source: AGHT+IEufjYDST/c2IiS727T9XeOkJ9gArcHB4Zxl0Qh6FhZoiHhLdT7WnQw8pYv1dT9+Ao1fE9e X-Received: by 2002:a81:6c8b:0:b0:604:33eb:14b0 with SMTP id h133-20020a816c8b000000b0060433eb14b0mr727102ywc.4.1707385067209; Thu, 08 Feb 2024 01:37:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707385067; cv=pass; d=google.com; s=arc-20160816; b=wYewGe+Rb+3jc0Jox0aEozYMsI8pR14wz54MXt3xkkG/JycWBBYubO04yCnd8ohYNQ 0OKnNdgD+Du7waBaqv20ALsjROTaFzT/AkbYF4No3Ddc2YYFtIMY9gJwO7VOtEZtxrXY nPW177gPTrw56Q+iKn1w3ielyqhZoHFDqPlU1F2hkFGUW8Nb9NUvYzYHhyfipUZ75uM5 uwql6rTRRoPbXoSdSrG2Q16YyuuHtgvtUyRj2JMqur97vRUBCHQJ1ysXFgqJ4BZtqrbm bdNgH1OT0xRfyhsnNuplMXM4baqmUKfCZOxXGf4d8pckkmMbWepUJXd87EMqfJNtFpOu Pe5A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter; bh=2icsXM4sghF71ROYFCFa6roBWVoViRGL+G2hZIeLN2Y=; fh=LzZqj3de13NnF27dCZODLEZyUkIkMmfRk8DRIhvYqJo=; b=P1oQ7lzuBYERb0+5IIlX56raVZwsyOmx/lskDHveHBJYSdzZReNTPTQHVfzQym3Hwp NZ7jAGHqz6jySSaa3nYkFWf1SxOkdFuDuDPlQ57fawk2WEAVNsnc11aP/8r/+eWG2T18 pxZ/106eV2SLi0ykQmwqYFS6x7G8prX4VZfiWP777m3NWJL5eZJmldyM+jVSnURrFfjr lHc1ZJGTEG1NMKig5dCtKR37trfiycA1BJb/AWF1RiXIh13RKc68p/koq5iB9gGeu3qB FYeAS1SWfFMd9oJOn/Vv6qXMVoB6Xixn2sJy59ua84mjB120ZEi36B52N9dskkB/t83m wQOA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=NVlOusRq; arc=pass (i=1 spf=pass spfdomain=ispras.ru dkim=pass dkdomain=ispras.ru dmarc=pass fromdomain=ispras.ru); spf=pass (google.com: domain of linux-kernel+bounces-57760-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57760-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru X-Forwarded-Encrypted: i=2; AJvYcCUlVhaDaZ5YnlKE14B0oR3aggOEEcVBjmy5paQYh1cAl0vxkqbx1+J7zzH/BafQH5wgyLALpaJVCnj2LwVH44spiQ+SLw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u14-20020a05622a14ce00b0042c2dc00774si2945488qtx.585.2024.02.08.01.37.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 01:37:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57760-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ispras.ru header.s=default header.b=NVlOusRq; arc=pass (i=1 spf=pass spfdomain=ispras.ru dkim=pass dkdomain=ispras.ru dmarc=pass fromdomain=ispras.ru); spf=pass (google.com: domain of linux-kernel+bounces-57760-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57760-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 048001C26A8B for ; Thu, 8 Feb 2024 09:37:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E5D706D1B6; Thu, 8 Feb 2024 09:37:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b="NVlOusRq" Received: from mail.ispras.ru (mail.ispras.ru [83.149.199.84]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B10D86BB2F; Thu, 8 Feb 2024 09:37:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.149.199.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707385045; cv=none; b=e6XCrUQWXCuiiT9cGf3kPdBj54jGhUkcAsIl2VB6n0gRJHpFHliDKGXrU83IlWZr2n/TVqb0zDS4mHiTwbgngL1GecWOVbGj8O28v2uhc9mqV0HpkKwY4awCM5fkkdD/qJDB/7cUUEdmzkxipJOPxXuND3MrWqZv90uKzQRqtAM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707385045; c=relaxed/simple; bh=3Q2iyKC4hyp8AoOZUqz27l11mkhP1r9E0t2phlEb+Ck=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=c1YQYn20twW76s7bKXM6rVrVzESYT0O6WTh8uR6zA7KKlndB9dvtKMXRfuWGR94Q3Txl782ZkogDSUZajP6HnCpwXZoIHxvsUlPCbmyAekrAHPxFeB85xCJ9keGdhL69/nKCqgBZXOL5+bPWRg8GoTLV7PEOTR4DJCiPR1UJonU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru; spf=pass smtp.mailfrom=ispras.ru; dkim=pass (1024-bit key) header.d=ispras.ru header.i=@ispras.ru header.b=NVlOusRq; arc=none smtp.client-ip=83.149.199.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ispras.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ispras.ru Received: from fpc.intra.ispras.ru (unknown [10.10.165.11]) by mail.ispras.ru (Postfix) with ESMTPSA id D37D740755CC; Thu, 8 Feb 2024 09:37:11 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru D37D740755CC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1707385031; bh=2icsXM4sghF71ROYFCFa6roBWVoViRGL+G2hZIeLN2Y=; h=From:To:Cc:Subject:Date:From; b=NVlOusRqo/vP1OrfsuqYNRGwY5C9++itFnlj14yUQ6+AwsQ4QEdlh5gLhmU3FDSW5 oMk7LvL1rPu3oPs9JkKZWAG3B1byV1SmiPnUNO91WvAl6BqSc0+vR/epcA74l4wAKF Cr+X0r7Gz8m/sOmOzhC/bpSLWGFLTmUsumy1sl0g= From: Fedor Pchelkin To: James Smart , "Martin K. Petersen" Cc: Fedor Pchelkin , Ram Vegesna , "James E.J. Bottomley" , Daniel Wagner , Hannes Reinecke , linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Alexey Khoroshilov , lvc-project@linuxtesting.org, stable@vger.kernel.org Subject: [PATCH] scsi: elx: efct: adjust error handling inside efct_hw_setup_io Date: Thu, 8 Feb 2024 12:36:57 +0300 Message-Id: <20240208093657.19617-1-pchelkin@ispras.ru> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790323004053212943 X-GMAIL-MSGID: 1790323004053212943 IO and WQE buffers are allocated once per HW and can be reused later. If WQE buffers allocation fails then the whole allocation is marked as failed but already created IO array internal objects are not freed. hw->io is freed but not nullified in that specific case - it may become a problem later as efct_hw_setup_io() is supposed to be reusable for the same HW. While at it, use kcalloc instead of kmalloc_array/memset-zero combination and get rid of some needless NULL assignments: nullifying hw->io[i] elements just before freeing hw->io is not really useful. Found by Linux Verification Center (linuxtesting.org). Fixes: 4df84e846624 ("scsi: elx: efct: Driver initialization routines") Cc: stable@vger.kernel.org Signed-off-by: Fedor Pchelkin --- drivers/scsi/elx/efct/efct_hw.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/elx/efct/efct_hw.c b/drivers/scsi/elx/efct/efct_hw.c index 5a5525054d71..e5486e6949f9 100644 --- a/drivers/scsi/elx/efct/efct_hw.c +++ b/drivers/scsi/elx/efct/efct_hw.c @@ -487,12 +487,10 @@ efct_hw_setup_io(struct efct_hw *hw) struct efct *efct = hw->os; if (!hw->io) { - hw->io = kmalloc_array(hw->config.n_io, sizeof(io), GFP_KERNEL); + hw->io = kcalloc(hw->config.n_io, sizeof(io), GFP_KERNEL); if (!hw->io) return -ENOMEM; - memset(hw->io, 0, hw->config.n_io * sizeof(io)); - for (i = 0; i < hw->config.n_io; i++) { hw->io[i] = kzalloc(sizeof(*io), GFP_KERNEL); if (!hw->io[i]) @@ -502,10 +500,8 @@ efct_hw_setup_io(struct efct_hw *hw) /* Create WQE buffs for IO */ hw->wqe_buffs = kzalloc((hw->config.n_io * hw->sli.wqe_size), GFP_KERNEL); - if (!hw->wqe_buffs) { - kfree(hw->io); - return -ENOMEM; - } + if (!hw->wqe_buffs) + goto error; } else { /* re-use existing IOs, including SGLs */ @@ -586,10 +582,8 @@ efct_hw_setup_io(struct efct_hw *hw) return 0; error: - for (i = 0; i < hw->config.n_io && hw->io[i]; i++) { + for (i = 0; i < hw->config.n_io && hw->io[i]; i++) kfree(hw->io[i]); - hw->io[i] = NULL; - } kfree(hw->io); hw->io = NULL;