Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp6110124pxb; Thu, 27 Jan 2022 06:46:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/+o8gsI/Rh42bgYjMwHptqgNtagYKJ4yDs0rAP3Jp5DxYOOTbgZ2zYJ78ycBW0gKPcjCW X-Received: by 2002:a05:6402:5186:: with SMTP id q6mr4003377edd.96.1643294759937; Thu, 27 Jan 2022 06:45:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643294759; cv=none; d=google.com; s=arc-20160816; b=BFAWIRB2IDu0orpeXaKc1hWEkTkSzzg7HBGDk3QBGairUX20ovW2adVjEb0+vN0Td5 5m4wCBhFDYXS+lzEBnrpBEA9EgL8C5MNqMyDo+etEZ0N/ELuBkekgHRXNx+xJUu4Fy2/ 2oCk9oxvNbDrflkP0Q7nw+CFmNXF5h2b426XaufxxdHjDuZajT4N/p0J8HtzwZ7JJp4K ldwzYNjINICn6h0iDaITGAzbr11KymsvzkLnSLbEay08qTEQyy81pACKC6bYgM/RfJVl ADr8vGT4+Fr9XkPXklvGNMMwnA7CLu39eEcVqxtXlPRv4Ivwgs+LsKjOWcwBWYHgGijy EzQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=EmazQ9E2wIfJZJtaZOCQWpGJtqttZ4RvP8Ex5frd7c4=; b=ceX1NU2DFne4kswo2R9w227+A5huXz9pfORm0cqs/kDbyO1ny1mID5AaNjbvgmO8yK YoByeYfKYZiHMoOEeLIzXXIiamm7XiZRympJx17gxPMje8FvZwNzdgnqozJw7fymK+0i 8XMRYxlWBlk0R694Z9MlRpaUPJo2MQsd1Af+lzdUevwQGinGg8N5OCJpUd+aCArHINtT d10p0Vc2Tv5YwIDiwONMVa3Ue1OTuxvXz6l9YuyfD5mCth/k/ef++IpRXVsHH49OuKwE 18neWy9KWrr3VYxlTM60w8WCgSH1KivOL2+Dvu11OTuij7NZ7849uDgfUeCMj4h3dwRB 7VQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dz14si1835165edb.150.2022.01.27.06.45.34; Thu, 27 Jan 2022 06:45:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238106AbiA0JAW (ORCPT + 99 others); Thu, 27 Jan 2022 04:00:22 -0500 Received: from smtpbg703.qq.com ([203.205.195.89]:36716 "EHLO smtpproxy21.qq.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238104AbiA0JAV (ORCPT ); Thu, 27 Jan 2022 04:00:21 -0500 X-QQ-mid: bizesmtp43t1643274007t8sa334g Received: from localhost.localdomain (unknown [58.240.82.166]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 27 Jan 2022 17:00:01 +0800 (CST) X-QQ-SSF: 0140000000200090E000C00A0000000 X-QQ-FEAT: nnjWNCC3Pd2Gry3AWSm/mVxwssU5xdxnJ6Cjs2RQO2G+C3WtpV0Qqw+SNMq6Z QqNpR1oggIOktD1eMsqTTnZL5c20GpnnhuFGCFe3xoXK/HOWo5N4g+O/ujWSqfG2+NX/AcY mMih7+jygtydz/MIWHkCHWIBf14OSibTBUG7XAv4qTPJ8fSkej5TOGMAdf1utKQr1BxH4/6 i/eOG+pVU7uGGOT921rNPNmdnQZqbejjB4NXQ0y6BMzu8VBmtPHdGMlZ99beKonIebh12lt wEe6QR9dMUjKFigKuU/ymL3kyzutMypM+YNvU3mlQmRCm4E+1om5xTCSiWy1v1LkbKN9rF9 00IgxAMjJ0nl8RdWofxotvfViRvNnke0a9jfK9sGYN82PjxlkI= X-QQ-GoodBg: 2 From: tangmeng To: axboe@kernel.dk, jejb@linux.ibm.com, martin.petersen@oracle.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: tangmeng Subject: [PATCH] scsi: sr: Improve the judgment statement Date: Thu, 27 Jan 2022 17:00:00 +0800 Message-Id: <20220127090000.5289-1-tangmeng@uniontech.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybgforeign:qybgforeign7 X-QQ-Bgrelay: 1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The previous code has a less-than-perfect usage of judgment syntax. When the med->media_event_code value is equal to 2 or 3, the same value is returned, so it would be better to combine the implementation statements when the med->media_event_code value is equal to 2 or 3. Moreover, when a variable is equal to multiple values, it is better to use a switch judgment statement. mechanical switch on the Drive) to eject the specified slot or media. Signed-off-by: tangmeng --- drivers/scsi/sr.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index f925b1f1f9ad..610baa630067 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -222,12 +222,16 @@ static unsigned int sr_get_events(struct scsi_device *sdev) if (eh->nea || eh->notification_class != 0x4) return 0; - if (med->media_event_code == 1) + switch (med->media_event_code) { + case 1: return DISK_EVENT_EJECT_REQUEST; - else if (med->media_event_code == 2) - return DISK_EVENT_MEDIA_CHANGE; - else if (med->media_event_code == 3) + case 2: + case 3: return DISK_EVENT_MEDIA_CHANGE; + default: + break; + } + return 0; } -- 2.20.1