Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp6115958pxb; Thu, 27 Jan 2022 06:53:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxsBNJx5Mv5B7ptaTiq1n1P9tQfiOzMJVuU2bKUSf8edp0CHoEhOVoY9PUn1xLEkC4wXijU X-Received: by 2002:aa7:97a4:: with SMTP id d4mr3230697pfq.85.1643295196387; Thu, 27 Jan 2022 06:53:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643295196; cv=none; d=google.com; s=arc-20160816; b=U6+wPMKkiY/qafvbIV6E0m6/uVjv+D9ENEwuqF5E3z/oFtNPtgUucCbtQCmjijicvN u1o14+oEFFJxpOJm2T2Ll4Zm7tSvOWTy6eVd04r22ZOC7a6jWgQmUzNH2PT73AEpu/aN Dq6vEBEy/5EUYnkfVAZtbfISut8+P0wu62AkghOAnFhc+1bNANCisJxY0zVzPehoyV8D 9B2rnPhyLfq+j7c1u04R55LdE0uuy3+sMVYsOOYv9bCSWud61VOl8b8o/vwV8Cp2ymZc IrTl/SfL7O8sqzdk2OjVtMHTgIujQX4FBPVWgFrETRIbKRBG2EroORDccsoqmlVngbJc vQIA== 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=aJxNXg7OdiqLKJi7zdV1ozXaImjwtX0dRBVP/kzQzwCZEiBGp2CPfs+lg1dUI6SXvy CMikR2hypgVmxphtaygPPooUxddLTIh1hrP3umaluGC4HP0E4G8xaK6D9+NGPt44tBTw nx8M5U3eHY5tuNRRUanYzxP0x2RPaEhnpUDSvG7ycbo+QXlUT2KpG+BU7Zo8zaB5LHQ4 A67+BBx1P0zuPLxn8TSfwuN/FrckleIC/i+YqQgPi8gaBZYp2pkUvx6LTLeGLlYoxkav 5BU/9OMz1NQ2LgGaZliigwaxUPhmVWToBFHXAADavaDRqjxDrdFQhIupHD9vYKbyhCw7 Enbg== 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 u5si2180726plz.74.2022.01.27.06.53.04; Thu, 27 Jan 2022 06:53:16 -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 S238312AbiA0JMt (ORCPT + 99 others); Thu, 27 Jan 2022 04:12:49 -0500 Received: from smtpbguseast1.qq.com ([54.204.34.129]:47276 "EHLO smtpbguseast1.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238299AbiA0JMj (ORCPT ); Thu, 27 Jan 2022 04:12:39 -0500 X-QQ-mid: bizesmtp54t1643274737tnh7xl4d Received: from localhost.localdomain (unknown [58.240.82.166]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 27 Jan 2022 17:12:11 +0800 (CST) X-QQ-SSF: 0140000000200090E000C00A0000000 X-QQ-FEAT: F3yR32iATbjWw3acDtsfp2HLqnilxm49/4xuiIAVnD3g9W5QKpqaUyV3Lkk6W GRHy/Z/TKb4rTYjEmDW/4bTNTdYtPjiVTdxpR3fJkmD5jxHf55vczWMU1TKeLG+bS2qg34p oXrvYyWnob/at2T9ngNQV+dHympfswqSoQLwtmOwDlZ4N58gZh+A+1FBUpfJSk2aQX9AFAq 6BcI1OWr/5nv8fuVRU4bSdtYiTlwYBIbH7YnbjB/Sh7m4ZXbdKG9HZhd4kcFD7Miact+6gP beikY47ZSxYMJ9tMuVcAIrZxqhYSln7ymbG4ntqkxzPwI/+Z1At6Kd/GL23LxJIzVkcRZnk oLYqJ4J/hEIwOLDpaM/Q91vzWiAvM5Z9Us9A37dR66jYSdju+I= 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:11:36 +0800 Message-Id: <20220127091136.9658-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. 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