Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp848918ybg; Wed, 23 Oct 2019 06:46:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqxIxJQ5AkW1D3u9um4eIiG8FZk5yce3gfWRC9Zcj3dFUaApSEABg2y2c/KagKN8G+r8RF8S X-Received: by 2002:a17:907:40bd:: with SMTP id nu21mr4507657ejb.190.1571838362136; Wed, 23 Oct 2019 06:46:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571838362; cv=none; d=google.com; s=arc-20160816; b=m3dEFGHL+YfCvyuS4y4InY0jbLlLQCITH0xN0vIhwPaAA+F9qjJAStm4SqJy0fz2UD pJxFZEkYmyVuvB5gcMAfS/rbl4+KpNbEGb23cpD2sZwTXfgEQH3zrmQOAv9Oek+nuGTt 6mAEwWa5s8UkvKnFK0r5YEDOS7kfWG7w0azSXVS+/xamj5x7RTlk/PRe3Ee7LqLwONEp svSak2V8CbjbX8YzhDqPs8nENfH2JykDin2jhA3v0M347XiIvXulrhSAECPRtdIMzOXG mOgY4RYmiGZLFRYXIwiQ3w+WtyEEPcC6ohm0injA1kJRfdXWvEJxLzCHDJ/0HhWu3sbZ H7/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Y2hfN3VWhFXFqfic2diBwcqQb9cpKPsxXvOi26gq91k=; b=ZhDT+6KJkJGVP9BpuVtV8IV0Az4YHM3+QGTEY86t+FYbuyoFhKj0+gaCMpuiofcqRu k/ibf1lcr7H70onp7YYZBus3hnlpLJjKrpcLHte7w4IFCH08KBtBIeKuY98pHvutlz09 hTVFLH+1cqqf2jF8p82ZV7lZxOJvdmsghMcG26yE4i9OgAy1ZN96OTDdrRftQVfirGqc x2wHGtKgfdLweIHBhH9nrMS4YaH8oR652mxPofq0VgSr93QbAEwXNp/Ex6jSg1EEoa0a xaW845Y+9z72X8cq7gtS7nUVVwKM8L0+Oc/dUOUkvaPfyk5IAk4M1gwMQ3mhpfoFkjoK wokg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r4si4779869ejb.296.2019.10.23.06.45.37; Wed, 23 Oct 2019 06:46:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391865AbfJWMxO (ORCPT + 99 others); Wed, 23 Oct 2019 08:53:14 -0400 Received: from mx2.suse.de ([195.135.220.15]:49314 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2391046AbfJWMxN (ORCPT ); Wed, 23 Oct 2019 08:53:13 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 161F5B670; Wed, 23 Oct 2019 12:53:10 +0000 (UTC) From: Michal Suchanek To: linux-scsi@vger.kernel.org Cc: Michal Suchanek , Jonathan Corbet , Jens Axboe , "James E.J. Bottomley" , "Martin K. Petersen" , Alexander Viro , Mauro Carvalho Chehab , Eric Biggers , "J. Bruce Fields" , Benjamin Coddington , Hannes Reinecke , Omar Sandoval , Ming Lei , Damien Le Moal , Bart Van Assche , Tejun Heo , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v2 2/8] cdrom: factor out common open_for_* code Date: Wed, 23 Oct 2019 14:52:41 +0200 Message-Id: X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The open_for_audio and open_for_data copies are bitrotten in different ways already and will need to update the autoclose logic in both. Signed-off-by: Michal Suchanek --- drivers/cdrom/cdrom.c | 96 +++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 62 deletions(-) diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index 2ad6b73482fe..f504ca70f93f 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c @@ -1046,12 +1046,12 @@ static void cdrom_count_tracks(struct cdrom_device_info *cdi, tracktype *tracks) } static -int open_for_data(struct cdrom_device_info *cdi) +int open_for_common(struct cdrom_device_info *cdi, tracktype *tracks) { int ret; const struct cdrom_device_ops *cdo = cdi->ops; - tracktype tracks; - cd_dbg(CD_OPEN, "entering open_for_data\n"); + + cd_dbg(CD_OPEN, "entering open_for_common\n"); /* Check if the driver can report drive status. If it can, we can do clever things. If it can't, well, we at least tried! */ if (cdo->drive_status != NULL) { @@ -1071,37 +1071,45 @@ int open_for_data(struct cdrom_device_info *cdi) couldn't close the tray. We only care that there is no disc in the drive, since that is the _REAL_ problem here.*/ - ret=-ENOMEDIUM; - goto clean_up_and_return; + return -ENOMEDIUM; } } else { cd_dbg(CD_OPEN, "bummer. this drive can't close the tray.\n"); - ret=-ENOMEDIUM; - goto clean_up_and_return; + return -ENOMEDIUM; } /* Ok, the door should be closed now.. Check again */ ret = cdo->drive_status(cdi, CDSL_CURRENT); if ((ret == CDS_NO_DISC) || (ret==CDS_TRAY_OPEN)) { cd_dbg(CD_OPEN, "bummer. the tray is still not closed.\n"); cd_dbg(CD_OPEN, "tray might not contain a medium\n"); - ret=-ENOMEDIUM; - goto clean_up_and_return; + return -ENOMEDIUM; } cd_dbg(CD_OPEN, "the tray is now closed\n"); } - /* the door should be closed now, check for the disc */ - ret = cdo->drive_status(cdi, CDSL_CURRENT); - if (ret!=CDS_DISC_OK) { - ret = -ENOMEDIUM; - goto clean_up_and_return; - } + if (ret != CDS_DISC_OK) + return -ENOMEDIUM; } - cdrom_count_tracks(cdi, &tracks); - if (tracks.error == CDS_NO_DISC) { + cdrom_count_tracks(cdi, tracks); + if (tracks->error == CDS_NO_DISC) { cd_dbg(CD_OPEN, "bummer. no disc.\n"); - ret=-ENOMEDIUM; - goto clean_up_and_return; + return -ENOMEDIUM; } + + return 0; +} + +static +int open_for_data(struct cdrom_device_info *cdi) +{ + int ret; + const struct cdrom_device_ops *cdo = cdi->ops; + tracktype tracks; + + cd_dbg(CD_OPEN, "entering open_for_data\n"); + ret = open_for_common(cdi, &tracks); + if (ret) + goto clean_up_and_return; + /* CD-Players which don't use O_NONBLOCK, workman * for example, need bit CDO_CHECK_TYPE cleared! */ if (tracks.data==0) { @@ -1208,53 +1216,17 @@ int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev, /* This code is similar to that in open_for_data. The routine is called whenever an audio play operation is requested. */ -static int check_for_audio_disc(struct cdrom_device_info *cdi, - const struct cdrom_device_ops *cdo) +static int check_for_audio_disc(struct cdrom_device_info *cdi) { int ret; tracktype tracks; cd_dbg(CD_OPEN, "entering check_for_audio_disc\n"); if (!(cdi->options & CDO_CHECK_TYPE)) return 0; - if (cdo->drive_status != NULL) { - ret = cdo->drive_status(cdi, CDSL_CURRENT); - cd_dbg(CD_OPEN, "drive_status=%d\n", ret); - if (ret == CDS_TRAY_OPEN) { - cd_dbg(CD_OPEN, "the tray is open...\n"); - /* can/may i close it? */ - if (CDROM_CAN(CDC_CLOSE_TRAY) && - cdi->options & CDO_AUTO_CLOSE) { - cd_dbg(CD_OPEN, "trying to close the tray\n"); - ret=cdo->tray_move(cdi,0); - if (ret) { - cd_dbg(CD_OPEN, "bummer. tried to close tray but failed.\n"); - /* Ignore the error from the low - level driver. We don't care why it - couldn't close the tray. We only care - that there is no disc in the drive, - since that is the _REAL_ problem here.*/ - return -ENOMEDIUM; - } - } else { - cd_dbg(CD_OPEN, "bummer. this driver can't close the tray.\n"); - return -ENOMEDIUM; - } - /* Ok, the door should be closed now.. Check again */ - ret = cdo->drive_status(cdi, CDSL_CURRENT); - if ((ret == CDS_NO_DISC) || (ret==CDS_TRAY_OPEN)) { - cd_dbg(CD_OPEN, "bummer. the tray is still not closed.\n"); - return -ENOMEDIUM; - } - if (ret!=CDS_DISC_OK) { - cd_dbg(CD_OPEN, "bummer. disc isn't ready.\n"); - return -EIO; - } - cd_dbg(CD_OPEN, "the tray is now closed\n"); - } - } - cdrom_count_tracks(cdi, &tracks); - if (tracks.error) - return(tracks.error); + + ret = open_for_common(cdi, &tracks); + if (ret) + return ret; if (tracks.audio==0) return -EMEDIUMTYPE; @@ -2725,7 +2697,7 @@ static int cdrom_ioctl_play_trkind(struct cdrom_device_info *cdi, if (copy_from_user(&ti, argp, sizeof(ti))) return -EFAULT; - ret = check_for_audio_disc(cdi, cdi->ops); + ret = check_for_audio_disc(cdi); if (ret) return ret; return cdi->ops->audio_ioctl(cdi, CDROMPLAYTRKIND, &ti); @@ -2773,7 +2745,7 @@ static int cdrom_ioctl_audioctl(struct cdrom_device_info *cdi, if (!CDROM_CAN(CDC_PLAY_AUDIO)) return -ENOSYS; - ret = check_for_audio_disc(cdi, cdi->ops); + ret = check_for_audio_disc(cdi); if (ret) return ret; return cdi->ops->audio_ioctl(cdi, cmd, NULL); -- 2.23.0