Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 31 Mar 2017 04:42:00 +0000 (UTC)
From:      Ngie Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r316316 - stable/10/lib/libcam
Message-ID:  <201703310442.v2V4g0JR056329@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ngie
Date: Fri Mar 31 04:42:00 2017
New Revision: 316316
URL: https://svnweb.freebsd.org/changeset/base/316316

Log:
  MFC r316080,r316081,r316115:
  
  r316080:
  
  Fix some localized style(9) issues and reword CAM_ERRBUF_SIZE description
  
  The CAM_ERRBUF_SIZE description rewording fixes a typo by proxy.
  
  r316081:
  
  Use `sizeof(cam_errbuf)` instead of `CAM_ERRBUF_SIZE` in snprintf calls
  
  Reindent snprintf calls' arguments to match style(9) guidelines with
  respect to indentation.
  
  r316115:
  
  libcam: use __func__ instead of hardcoding the function name as `func_name`
  
  Tested with:	`cam_device_copy(NULL, NULL)` // ;)..

Modified:
  stable/10/lib/libcam/camlib.c
  stable/10/lib/libcam/camlib.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libcam/camlib.c
==============================================================================
--- stable/10/lib/libcam/camlib.c	Fri Mar 31 03:11:25 2017	(r316315)
+++ stable/10/lib/libcam/camlib.c	Fri Mar 31 04:42:00 2017	(r316316)
@@ -114,16 +114,14 @@ cam_freeccb(union ccb *ccb)
 int
 cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit)
 {
-	char *func_name = "cam_get_device";
 	char *tmpstr, *tmpstr2;
 	char *newpath;
 	int unit_offset;
 	int i;
 
-
 	if (path == NULL) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: device pathname was NULL", func_name);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: device pathname was NULL", __func__);
 		return(-1);
 	}
 
@@ -145,8 +143,8 @@ cam_get_device(const char *path, char *d
 	}
 
 	if (*tmpstr == '\0') {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: no text after slash", func_name);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: no text after slash", __func__);
 		free(newpath);
 		return(-1);
 	}
@@ -173,9 +171,9 @@ cam_get_device(const char *path, char *d
 	 * If we only have 1, we don't have a valid device name.
 	 */
 	if (strlen(tmpstr) < 2) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: must have both device name and unit number",
-			 func_name);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: must have both device name and unit number",
+		    __func__);
 		free(newpath);
 		return(-1);
 	}
@@ -185,9 +183,9 @@ cam_get_device(const char *path, char *d
 	 * has probably given us all numbers.  Point out the error.
 	 */
 	if (isdigit(*tmpstr)) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: device name cannot begin with a number",
-			 func_name);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: device name cannot begin with a number",
+		    __func__);
 		free(newpath);
 		return(-1);
 	}
@@ -198,8 +196,8 @@ cam_get_device(const char *path, char *d
 	 * or he gave us a device name/number format we don't recognize.
 	 */
 	if (!isdigit(tmpstr[strlen(tmpstr) - 1])) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: unable to find device unit number", func_name);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: unable to find device unit number", __func__);
 		free(newpath);
 		return(-1);
 	}
@@ -271,13 +269,12 @@ cam_open_btl(path_id_t path_id, target_i
 {
 	union ccb ccb;
 	struct periph_match_pattern *match_pat;
-	char *func_name = "cam_open_btl";
 	int fd, bufsize;
 
 	if ((fd = open(XPT_DEVICE, O_RDWR)) < 0) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: couldn't open %s\n%s: %s", func_name, XPT_DEVICE,
-			 func_name, strerror(errno));
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: couldn't open %s\n%s: %s", __func__, XPT_DEVICE,
+		    __func__, strerror(errno));
 		return(NULL);
 	}
 
@@ -292,8 +289,8 @@ cam_open_btl(path_id_t path_id, target_i
 	ccb.cdm.match_buf_len = bufsize;
 	ccb.cdm.matches = (struct dev_match_result *)malloc(bufsize);
 	if (ccb.cdm.matches == NULL) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: couldn't malloc match buffer", func_name);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: couldn't malloc match buffer", __func__);
 		close(fd);
 		return(NULL);
 	}
@@ -305,8 +302,8 @@ cam_open_btl(path_id_t path_id, target_i
 	ccb.cdm.patterns = (struct dev_match_pattern *)malloc(
 		sizeof(struct dev_match_pattern));
 	if (ccb.cdm.patterns == NULL) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: couldn't malloc pattern buffer", func_name);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: couldn't malloc pattern buffer", __func__);
 		free(ccb.cdm.matches);
 		ccb.cdm.matches = NULL;
 		close(fd);
@@ -328,9 +325,9 @@ cam_open_btl(path_id_t path_id, target_i
 			   PERIPH_MATCH_LUN | PERIPH_MATCH_NAME;
 
 	if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: CAMIOCOMMAND ioctl failed\n"
-			 "%s: %s", func_name, func_name, strerror(errno));
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: CAMIOCOMMAND ioctl failed\n"
+		    "%s: %s", __func__, __func__, strerror(errno));
 		goto btl_bailout;
 	}
 
@@ -340,26 +337,26 @@ cam_open_btl(path_id_t path_id, target_i
 	if ((ccb.ccb_h.status != CAM_REQ_CMP)
 	 || ((ccb.cdm.status != CAM_DEV_MATCH_LAST)
 	   && (ccb.cdm.status != CAM_DEV_MATCH_MORE))) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: CAM error %#x, CDM error %d "
-			 "returned from XPT_DEV_MATCH ccb", func_name,
-			 ccb.ccb_h.status, ccb.cdm.status);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: CAM error %#x, CDM error %d "
+		    "returned from XPT_DEV_MATCH ccb", __func__,
+		    ccb.ccb_h.status, ccb.cdm.status);
 		goto btl_bailout;
 	}
 
 	if (ccb.cdm.status == CAM_DEV_MATCH_MORE) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: CDM reported more than one"
-			 " passthrough device at %d:%d:%jx!!\n",
-			 func_name, path_id, target_id, (uintmax_t)target_lun);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: CDM reported more than one"
+		    " passthrough device at %d:%d:%jx!!\n",
+		    __func__, path_id, target_id, (uintmax_t)target_lun);
 		goto btl_bailout;
 	}
 
 	if (ccb.cdm.num_matches == 0) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: no passthrough device found at"
-			 " %d:%d:%jx", func_name, path_id, target_id,
-			 (uintmax_t)target_lun);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: no passthrough device found at"
+		    " %d:%d:%jx", __func__, path_id, target_id,
+		    (uintmax_t)target_lun);
 		goto btl_bailout;
 	}
 
@@ -382,9 +379,9 @@ cam_open_btl(path_id_t path_id, target_i
 		break; /* NOTREACHED */
 	}
 	default:
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: asked for a peripheral match, but"
-			 " got a bus or device match", func_name);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: asked for a peripheral match, but"
+		    " got a bus or device match", __func__);
 		goto btl_bailout;
 		break; /* NOTREACHED */
 	}
@@ -418,7 +415,6 @@ cam_lookup_pass(const char *dev_name, in
 	int fd;
 	union ccb ccb;
 	char dev_path[256];
-	char *func_name = "cam_lookup_pass";
 
 	/*
 	 * The flags argument above only applies to the actual passthrough
@@ -426,9 +422,9 @@ cam_lookup_pass(const char *dev_name, in
 	 * passthrough device.
 	 */
 	if ((fd = open(XPT_DEVICE, O_RDWR)) < 0) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: couldn't open %s\n%s: %s", func_name, XPT_DEVICE,
-			 func_name, strerror(errno));
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: couldn't open %s\n%s: %s", __func__, XPT_DEVICE,
+		    __func__, strerror(errno));
 		return(NULL);
 	}
 
@@ -457,12 +453,12 @@ cam_lookup_pass(const char *dev_name, in
 			snprintf(tmpstr, sizeof(tmpstr),
 				 "\n%s: either the pass driver isn't in "
 				 "your kernel\n%s: or %s%d doesn't exist",
-				 func_name, func_name, dev_name, unit);
+				 __func__, __func__, dev_name, unit);
 		}
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: CAMGETPASSTHRU ioctl failed\n"
-			 "%s: %s%s", func_name, func_name, strerror(errno),
-			 (errno == ENOENT) ? tmpstr : "");
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: CAMGETPASSTHRU ioctl failed\n"
+		    "%s: %s%s", __func__, __func__, strerror(errno),
+		    (errno == ENOENT) ? tmpstr : "");
 
 		close(fd);
 		return(NULL);
@@ -477,9 +473,9 @@ cam_lookup_pass(const char *dev_name, in
 	 * the device the user gave us.
 	 */
 	if (ccb.cgdl.status == CAM_GDEVLIST_ERROR) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: device %s%d does not exist!",
-			 func_name, dev_name, unit);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: device %s%d does not exist!",
+		    __func__, dev_name, unit);
 		return(NULL);
 	}
 
@@ -499,7 +495,6 @@ cam_real_open_device(const char *path, i
 		     const char *given_path, const char *given_dev_name,
 		     int given_unit_number)
 {
-	char *func_name = "cam_real_open_device";
 	union ccb ccb;
 	int fd = -1, malloced_device = 0;
 
@@ -509,10 +504,10 @@ cam_real_open_device(const char *path, i
 	if (device == NULL) {
 		if ((device = (struct cam_device *)malloc(
 		     sizeof(struct cam_device))) == NULL) {
-			snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-				 "%s: device structure malloc"
-				 " failed\n%s: %s", func_name, func_name,
-				 strerror(errno));
+			snprintf(cam_errbuf, sizeof(cam_errbuf),
+			    "%s: device structure malloc"
+			    " failed\n%s: %s", __func__, __func__,
+			    strerror(errno));
 			return(NULL);
 		}
 		device->fd = -1;
@@ -540,10 +535,10 @@ cam_real_open_device(const char *path, i
 	device->given_unit_number = given_unit_number;
 
 	if ((fd = open(path, flags)) < 0) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: couldn't open passthrough device %s\n"
-			 "%s: %s", func_name, path, func_name,
-			 strerror(errno));
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: couldn't open passthrough device %s\n"
+		    "%s: %s", __func__, path, __func__,
+		    strerror(errno));
 		goto crod_bailout;
 	}
 
@@ -568,9 +563,9 @@ cam_real_open_device(const char *path, i
 		 * because we just opened it above.  The only way this
 		 * ioctl can fail is if the ccb size is wrong.
 		 */
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: CAMGETPASSTHRU ioctl failed\n"
-			 "%s: %s", func_name, func_name, strerror(errno));
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: CAMGETPASSTHRU ioctl failed\n"
+		    "%s: %s", __func__, __func__, strerror(errno));
 		goto crod_bailout;
 	}
 
@@ -581,8 +576,8 @@ cam_real_open_device(const char *path, i
 	 * the device the user gave us.
 	 */
 	if (ccb.cgdl.status == CAM_GDEVLIST_ERROR) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: passthrough device does not exist!", func_name);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: passthrough device does not exist!", __func__);
 		goto crod_bailout;
 	}
 
@@ -595,9 +590,9 @@ cam_real_open_device(const char *path, i
 
 	ccb.ccb_h.func_code = XPT_PATH_INQ;
 	if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: Path Inquiry CCB failed\n"
-			 "%s: %s", func_name, func_name, strerror(errno));
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: Path Inquiry CCB failed\n"
+		    "%s: %s", __func__, __func__, strerror(errno));
 		goto crod_bailout;
 	}
 	strlcpy(device->sim_name, ccb.cpi.dev_name, sizeof(device->sim_name));
@@ -610,9 +605,9 @@ cam_real_open_device(const char *path, i
 	 */
 	ccb.ccb_h.func_code = XPT_GDEV_TYPE;
 	if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: Get Device Type CCB failed\n"
-			 "%s: %s", func_name, func_name, strerror(errno));
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: Get Device Type CCB failed\n"
+		    "%s: %s", __func__, __func__, strerror(errno));
 		goto crod_bailout;
 	}
 	device->pd_type = SID_TYPE(&ccb.cgd.inq_data);
@@ -634,9 +629,9 @@ cam_real_open_device(const char *path, i
 	ccb.cts.type = CTS_TYPE_CURRENT_SETTINGS;
 
 	if (ioctl(fd, CAMIOCOMMAND, &ccb) == -1) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: Get Transfer Settings CCB failed\n"
-			 "%s: %s", func_name, func_name, strerror(errno));
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: Get Transfer Settings CCB failed\n"
+		    "%s: %s", __func__, __func__, strerror(errno));
 		goto crod_bailout;
 	}
 	if (ccb.cts.transport == XPORT_SPI) {
@@ -713,20 +708,19 @@ cam_path_string(struct cam_device *dev, 
 struct cam_device *
 cam_device_dup(struct cam_device *device)
 {
-	char *func_name = "cam_device_dup";
 	struct cam_device *newdev;
 
 	if (device == NULL) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: device is NULL", func_name);
-		return(NULL);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: device is NULL", __func__);
+		return (NULL);
 	}
 
 	newdev = malloc(sizeof(struct cam_device));
 	if (newdev == NULL) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			"%s: couldn't malloc CAM device structure", func_name);
-		return(NULL);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: couldn't malloc CAM device structure", __func__);
+		return (NULL);
 	}
 
 	bcopy(device, newdev, sizeof(struct cam_device));
@@ -740,17 +734,16 @@ cam_device_dup(struct cam_device *device
 void
 cam_device_copy(struct cam_device *src, struct cam_device *dst)
 {
-	char *func_name = "cam_device_copy";
 
 	if (src == NULL) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: source device struct was NULL", func_name);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: source device struct was NULL", __func__);
 		return;
 	}
 
 	if (dst == NULL) {
-		snprintf(cam_errbuf, CAM_ERRBUF_SIZE,
-			 "%s: destination device struct was NULL", func_name);
+		snprintf(cam_errbuf, sizeof(cam_errbuf),
+		    "%s: destination device struct was NULL", __func__);
 		return;
 	}
 

Modified: stable/10/lib/libcam/camlib.h
==============================================================================
--- stable/10/lib/libcam/camlib.h	Fri Mar 31 03:11:25 2017	(r316315)
+++ stable/10/lib/libcam/camlib.h	Fri Mar 31 04:42:00 2017	(r316316)
@@ -70,13 +70,13 @@
 #include <cam/cam.h>
 #include <cam/cam_ccb.h>
 
-#define CAM_ERRBUF_SIZE 2048	/* sizeof the CAM libarary error string  */
+#define	CAM_ERRBUF_SIZE 2048	/* CAM library error string size */
 
 /*
  * Right now we hard code the transport layer device, but this will change
  * if we ever get more than one transport layer.
  */
-#define XPT_DEVICE	"/dev/xpt0"
+#define	XPT_DEVICE	"/dev/xpt0"
 
 
 extern char cam_errbuf[];



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703310442.v2V4g0JR056329>