Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp928735lqp; Thu, 23 May 2024 04:34:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUhC0/GtEv7hxbVoE7wq20k3KByVUwr5+CPA2mr+8YDdRCj1mRF6tdBg0wEajwg2hs1ZTzgsxBF1a0o2hWCDvdaMO/P0G2Q5UJgRVRGLg== X-Google-Smtp-Source: AGHT+IGJeNu56Z0hJ/rUskpi1/8ZjKV20wYtspUN3VKbnbkMgGWDZOlIggy90eKoNd3o4bhFkcj4 X-Received: by 2002:a05:6a20:4325:b0:1af:e09d:d98 with SMTP id adf61e73a8af0-1b1f8b66c6emr5331991637.60.1716464088826; Thu, 23 May 2024 04:34:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716464088; cv=pass; d=google.com; s=arc-20160816; b=jU62P+WCTliPkFZAg2veu5hLYGEa9L36Q3MP8kQsm1lcd2JhlJYVnLfomQjdVqrsHC eOequSuCc5tFv3JQ/PhcKcD1YWLE1oWhDZjZIE2WUSWXJR6rOkZjoe2chKo37sHLwREq 3lfhrh94da8RaA8yiM8UQnsZ5bcgni2JhvO1nd709zuumD7DbEAzSwCEYEjeueExilaH 3mzdYSUeQPmOWiAFzPL2h212YMozjXEacG2ltw6pQ5p+BhXLoXR/ZcfekXanyju/+akc rXbrSNCyI4iYawoQqr045tJzN1UboHFqeeIuiHFD9Mv1hpUzu/UoamUSpeOrhVwHWI0O 9eyw== 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; bh=eshNdi8MhibtA7UrHJyZzzh5soo9ttxdAWbEOJelcIk=; fh=SpII9x/ZRe3NIa2acvvNTyMpJ/QlGuIGfqY2ig03wOc=; b=iERbElW8T+vcZARf46NeMet7hEcZWKe51gFUsUXVJrADIEfr+3R3pjDlLEBcONrOfV sdcP9mJRImQS8LCjYZn7QlX5Yo2Ogp5szASM6ZmH1QIhlkM9UZd7joPKnJLUxUO5btwn ralRxvkR81RrAetlozmjg+nvUqQ5DcsxaT8erJm4WnygHqN5D2O4zg5ESy11X6ANQidu 5Cb5Z5Nsdv4s2YCevRi5ZxGSnVCi0IaAyttgCZIppJeCnkBEbSeuYsBKN5X3/Kbi13d2 A2qDn5/RcMp7ilFfMzEoqtmVHgICuIySw9S/fe43IKWsU0T3dmyJ6SjaCz+dm6w5jdcF yM4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NycWAibO; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-187404-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187404-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-66d8955c564si4354027a12.898.2024.05.23.04.34.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 04:34:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-187404-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=NycWAibO; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-187404-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-187404-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 2166128357F for ; Thu, 23 May 2024 11:34:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F9C11487D0; Thu, 23 May 2024 11:34:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NycWAibO" Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19214BA2F; Thu, 23 May 2024 11:34:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716464078; cv=none; b=kbaNwJwyeskX+EhpjZtFyU9AMpm/0huIJ3WCZ3GS6M/rcaYo9QNNS41Ooic+VPDGy8a2taq5c0BbiRdZtEIAYiSHWC/Mx3K3V6wRRGEa1/IlvGibKqnnuub9lJ+L7xNEQLzh0nSmGH8buKwoNsSUugU4LTNaYcCnew4tI+w8/yA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716464078; c=relaxed/simple; bh=CeK6Tivq/xGw727Ec9ebA2/E9iSfftkX0NerKQy2wQw=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=TUdHUL6MrSscSFIyNvmosysnHBH+rdUIqUSIqTUpqKa85KsYGfpvXu/9EWKISdPEGicS0L2MnjAaaA1/YuV+zAXlIm/d1aI+w1IV97Zurfl6NqSGi+p1w1YCf6tadNKhoDaM/Pjz2cvbsOPS6nMZy3oR5mR3cVP6pfpAlQSO3W4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NycWAibO; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1ed96772f92so19999785ad.0; Thu, 23 May 2024 04:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716464076; x=1717068876; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=eshNdi8MhibtA7UrHJyZzzh5soo9ttxdAWbEOJelcIk=; b=NycWAibOW69+jxe0TTJkC34lE2CMXuOM5SQK6LX9vKk4Y1Nm0slBLZHO1UnS+sq7++ afSFbOaiHo92BsFebsigFLu/bSHrWELXoaKUkIE5qMigXYitRQIt3D+CmlJVXr4lfTRl FcMgDHeU0HCryg7dEwd1MeSi9zC/BC7qJ0LjXSz6XWQIfAKsylAWh+w5Lr+SbOp+tDx2 1yAgGRgzmrc9Vlkup5qcjS900bErUiWdgZKZu3Q03G1STlHi2HlRa6r1LH9TWB7K8c77 s97Tyj27aSYigXeRBv4a72cLXMzOVlr3qaLZeT59tEOcUkLuJWXN/XUN4vcFljyVp4rm OaXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716464076; x=1717068876; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eshNdi8MhibtA7UrHJyZzzh5soo9ttxdAWbEOJelcIk=; b=Rcmro49aCSn/OWg8cuEzlees0GSdY7yx5Eo2Q8zdTMWtBxKj7mWHdSWw1ANZgtc6lC OktV6/3Qxfm/0iTInKruxPc7OvkaP6URYvHnKkb7Cg524UcWbmycXiG9cWvRTyXGlBrW ZQ2gy3ieXrS3yUDGiHAasHTMIzd2+NwOx7nXh37oe533fg3nF6D9YmuWSk17gHsq263T zk8gdZyibJgDeTKiAKNJlbG/yNivHDP4x2e2g2q4qLcC+bM32pRRDHPTGR4L6djvYbG1 ta3KmavyhLSnsmbG2BF0ZAdZNvfp0q3IqHMJs1zjN4qba0MCKsdUaHjmOGbTVAkpunPT 9w1g== X-Forwarded-Encrypted: i=1; AJvYcCVqqMmpadv0bot8r3qlnxwHgjv7REZfT6luL3MKNX81TpiAhWyAsJ/B00aL9nZLv2wKPC5KxgdqcIZcBztXg4S757I0iV0jS8exQdyn X-Gm-Message-State: AOJu0Yx7zfNZVJx9hLEKRumpqBumrGdDkvWfRGL571+UF00sROownyuh CXk4bJuklg1UOtlHN0lEEBzFNoHqvQVJT+AJoXeBGO/G1dfONFJI X-Received: by 2002:a17:903:950:b0:1eb:144f:63b7 with SMTP id d9443c01a7336-1f31c9e173bmr56580715ad.56.1716464076410; Thu, 23 May 2024 04:34:36 -0700 (PDT) Received: from velvet.. ([111.42.148.111]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f0958fd757sm146846395ad.45.2024.05.23.04.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 04:34:36 -0700 (PDT) From: Shichao Lai To: stern@rowland.harvard.edu, gregkh@linuxfoundation.org, oneukum@suse.com Cc: linux-usb@vger.kernel.org, usb-storage@lists.one-eyed-alien.net, linux-kernel@vger.kernel.org, Shichao Lai , xingwei lee , yue sun Subject: [PATCH v2] usb-storage: Check whether divisor is non-zero before division Date: Thu, 23 May 2024 19:34:10 +0800 Message-Id: <20240523113410.983875-1-shichaorai@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Since uzonesize may be zero, so judgements for non-zero are nessesary in both place. Changes since v1: - Add one more check in alauda_write_lba(). - Move check ahead of loop in alauda_read_data(). Reported-by: xingwei lee Reported-by: yue sun Signed-off-by: Shichao Lai --- drivers/usb/storage/alauda.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c index 115f05a6201a..17c73acd3b02 100644 --- a/drivers/usb/storage/alauda.c +++ b/drivers/usb/storage/alauda.c @@ -813,6 +813,8 @@ static int alauda_write_lba(struct us_data *us, u16 lba, unsigned char ecc[3]; int i, result; unsigned int uzonesize = MEDIA_INFO(us).uzonesize; + if (!uzonesize) + return USB_STOR_TRANSPORT_ERROR; unsigned int zonesize = MEDIA_INFO(us).zonesize; unsigned int pagesize = MEDIA_INFO(us).pagesize; unsigned int blocksize = MEDIA_INFO(us).blocksize; @@ -921,6 +923,8 @@ static int alauda_read_data(struct us_data *us, unsigned long address, unsigned int blocksize = MEDIA_INFO(us).blocksize; unsigned int pagesize = MEDIA_INFO(us).pagesize; unsigned int uzonesize = MEDIA_INFO(us).uzonesize; + if (!uzonesize) + return USB_STOR_TRANSPORT_ERROR; struct scatterlist *sg; int result; -- 2.34.1