From owner-svn-src-stable@freebsd.org Tue Feb 28 23:56:25 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C497BCF2BCF; Tue, 28 Feb 2017 23:56:25 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9BF31A2E; Tue, 28 Feb 2017 23:56:25 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v1SNuOQQ011390; Tue, 28 Feb 2017 23:56:24 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v1SNuOKK011389; Tue, 28 Feb 2017 23:56:24 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201702282356.v1SNuOKK011389@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Tue, 28 Feb 2017 23:56:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r314439 - stable/11/usr.sbin/camdd X-SVN-Group: stable-11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Feb 2017 23:56:25 -0000 Author: asomers Date: Tue Feb 28 23:56:24 2017 New Revision: 314439 URL: https://svnweb.freebsd.org/changeset/base/314439 Log: MFC r312559: Fix misc Coverity defects in camdd(8) CID 1341620 Fix a small memory leak CID 1341630 Though this is technically a false positive, rearrange the code for clarity. CID 1341635 Eliminate dead code CID 1368663 Fix a double mutex unlock in the error path Also: * Use sig_atomic_t for variables accessed from signal handlers * Don't conditionalize free(3) on its argument being non-null Reported by: Coverity CID: 1341620 1341630 1341635 1368663 Reviewed by: ken MFC after: 4 weeks Sponsored by: Spectra Logic Corp Differential Revision: https://reviews.freebsd.org/D9237 Modified: stable/11/usr.sbin/camdd/camdd.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/camdd/camdd.c ============================================================================== --- stable/11/usr.sbin/camdd/camdd.c Tue Feb 28 23:56:14 2017 (r314438) +++ stable/11/usr.sbin/camdd/camdd.c Tue Feb 28 23:56:24 2017 (r314439) @@ -420,9 +420,9 @@ struct camdd_dev { }; static sem_t camdd_sem; -static int need_exit = 0; -static int error_exit = 0; -static int need_status = 0; +static sig_atomic_t need_exit = 0; +static sig_atomic_t error_exit = 0; +static sig_atomic_t need_status = 0; #ifndef min #define min(a, b) (a < b) ? a : b @@ -712,11 +712,7 @@ camdd_alloc_buf(struct camdd_dev *dev, c return (buf); bailout_error: - if (data_ptr != NULL) - free(data_ptr); - - if (buf != NULL) - free(buf); + free(data_ptr); return (NULL); } @@ -2262,6 +2258,7 @@ camdd_file_run(struct camdd_dev *dev) if (file_dev->tmp_buf == NULL) { buf->status = CAMDD_STATUS_ERROR; error_count++; + pthread_mutex_lock(&dev->mutex); goto bailout; } for (i = 0, cur_offset = 0; i < data->sg_count; i++) { @@ -2984,7 +2981,6 @@ int camdd_rw(struct camdd_io_opts *io_opts, int num_io_opts, uint64_t max_io, int retry_count, int timeout) { - char *device = NULL; struct cam_device *new_cam_dev = NULL; struct camdd_dev *devs[2]; struct timespec start_time; @@ -3004,12 +3000,11 @@ camdd_rw(struct camdd_io_opts *io_opts, for (i = 0; i < num_io_opts; i++) { switch (io_opts[i].dev_type) { case CAMDD_DEV_PASS: { - camdd_argmask new_arglist = CAMDD_ARG_NONE; - int bus = 0, target = 0, lun = 0; - char name[30]; - int rv; - if (isdigit(io_opts[i].dev_name[0])) { + camdd_argmask new_arglist = CAMDD_ARG_NONE; + int bus = 0, target = 0, lun = 0; + int rv; + /* device specified as bus:target[:lun] */ rv = parse_btl(io_opts[i].dev_name, &bus, &target, &lun, &new_arglist); @@ -3025,23 +3020,21 @@ camdd_rw(struct camdd_io_opts *io_opts, lun = 0; new_arglist |= CAMDD_ARG_LUN; } + new_cam_dev = cam_open_btl(bus, target, lun, + O_RDWR, NULL); } else { + char name[30]; + if (cam_get_device(io_opts[i].dev_name, name, sizeof name, &unit) == -1) { warnx("%s", cam_errbuf); error = 1; goto bailout; } - device = strdup(name); - new_arglist |= CAMDD_ARG_DEVICE |CAMDD_ARG_UNIT; + new_cam_dev = cam_open_spec_device(name, unit, + O_RDWR, NULL); } - if (new_arglist & (CAMDD_ARG_BUS | CAMDD_ARG_TARGET)) - new_cam_dev = cam_open_btl(bus, target, lun, - O_RDWR, NULL); - else - new_cam_dev = cam_open_spec_device(device, unit, - O_RDWR, NULL); if (new_cam_dev == NULL) { warnx("%s", cam_errbuf); error = 1;