Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp6113505pxb; Thu, 27 Jan 2022 06:50:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwkfxzAzyMv/+VOxpGam3U4c0tfmOmpCkg9Hth/RIxXWrNStJwzeHYJvAkEHcQK+PkkHbH0 X-Received: by 2002:a05:6a00:22c9:: with SMTP id f9mr3251910pfj.79.1643295017893; Thu, 27 Jan 2022 06:50:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643295017; cv=none; d=google.com; s=arc-20160816; b=FM6KwgOkiQoFB2H8DNrYyhRDoVp/6rCmYN5Cu8Wcref1lAnnbAPHJiyVwzYjhAkt1c jDF+b0XJbDbFBktd35pmVpKnQ2Fg9IImfJ25gW0gzGW7wo6yVGkpoA7WNAFZ4pf5t4w7 sLHXhXEOih4Mx4BgW0xj1R20fIrOfhmbQvMgp2DfFnd63vtlQPx120CAhr76R/mKxpO/ oP9bqq/+Dp+U9xki8qD5On6RC6tPvS+9mPYnhhdASAJQUPMY0Z2v0/tZk3bICyfkZojo FOGCg0m0MJXB775UDC9pp/qswqO4XypnWFIW2c6Bw8jP4IDTtQC9Vd8sWzJRYcp9ZC92 J5zA== 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=l4wDF4zJAt7Cogq0/807TTbhifTDqu0WWiD6MLi+gbg=; b=BJTBq/tJB42zag8lt44YU7KsdKdLhij30C6JfDTeCTl+dA1CUahE+eYt4m7FrqVrmA meMdISCdoxGEInFXUNyUntfxi9kD6FZ3w+hpZ6znoAsFtFqw/G5i/5/MwcntD85dTtoz SEjuc5RKYenLZ+UeGWb2sw+nMDJ/qwnn7e0pA9BZhBXXXM+NHioawBM82tbkMcYTX0XO S2CplGzefjSQyosHfPmnWbPQ6oPypNyXucAeAL4ur4bURHB+NFPeFNtJ8DYrDuEkqGoC dlJ255bJH/n3F3yF1rLH1TesxDDocbk7mZqpt3fEKB1MsL7xcs8d987i3E86oKjWg1ga E01A== 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 w12si2311515pgs.431.2022.01.27.06.50.05; Thu, 27 Jan 2022 06:50:17 -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 S238218AbiA0JIf (ORCPT + 99 others); Thu, 27 Jan 2022 04:08:35 -0500 Received: from smtpbg703.qq.com ([203.205.195.89]:46289 "EHLO smtpproxy21.qq.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229487AbiA0JIc (ORCPT ); Thu, 27 Jan 2022 04:08:32 -0500 X-QQ-mid: bizesmtp2t1643274495tyh25xokj Received: from localhost.localdomain (unknown [58.240.82.166]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 27 Jan 2022 17:08:08 +0800 (CST) X-QQ-SSF: 0140000000200090E000C00A0000000 X-QQ-FEAT: TskX/GkkryBPF5HT0HtElpIA2By6DbVGrlZBlksv/OSb1ADRISEZBY7nx878I p1NVq/zYH9i4AZJrcRVPtAWnot/SnvtEI1zRyJHwd2jUGAde8dvgP9kqTazKIwQIfXr60vS se60qq76pZOowKThJYNnLF+n8+fQ5dRB0QUMQIrfOTOmp5dZOsH27YltfXWsz9/ihVAdKU8 zWGj4pjowRG1HSmzqc8n9RKt17YbdNTCHXQlP4he81tWMzq1s3e0vVIYb/X1Ggg6ltHjN4p 6NujUGwzqqfEfK3KhF+e9xjIH3xUaq7ZIwdnGr6+5H9UMKFy66Dt0TgA6X+zLwYfbK0nfMQ wKjYZwa4+Sgj7b74hTOG/YG8oJhHFz0ieqOtLRhrwQQF/7/Ry8= 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 v2] scsi: sr: Improve the judgment statement Date: Thu, 27 Jan 2022 17:08:06 +0800 Message-Id: <20220127090806.8201-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:qybgforeign6 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. 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