Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

target: Make core_scsi3_update_and_write_aptpl return sense_reason_t

Fix up sense_reason_t breakage in core_scsi3_update_and_write_aptpl()
from recent conversion to use local scope memory allocation.

Reported as sparse warnings: (new ones prefixed by >>) by Fengguang:

>> drivers/target/target_core_pr.c:2069:57: sparse: incorrect type in
>> return expression (different base types)
drivers/target/target_core_pr.c:2069:57: expected restricted sense_reason_t
drivers/target/target_core_pr.c:2069:57: got int
>> drivers/target/target_core_pr.c:2179:21: sparse: incorrect type in
>> assignment (different base types)
drivers/target/target_core_pr.c:2179:21: expected restricted sense_reason_t [assigned] [usertype] ret
drivers/target/target_core_pr.c:2179:21: got int
>> drivers/target/target_core_pr.c:2197:13: sparse: incorrect type in
>> assignment (different base types)
drivers/target/target_core_pr.c:2197:13: expected restricted sense_reason_t [assigned] [usertype] ret
drivers/target/target_core_pr.c:2197:13: got int
drivers/target/target_core_pr.c:1245:28: sparse: context imbalance in '__core_scsi3_free_registration' - unexpected unlock

Reported-by: kbuild test robot <fengguang.wu@intel.com>
Cc: Andy Grover <agrover@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

+27 -24
+27 -24
drivers/target/target_core_pr.c
··· 1956 1956 * Clear the APTPL metadata if APTPL has been disabled, otherwise 1957 1957 * write out the updated metadata to struct file for this SCSI device. 1958 1958 */ 1959 - static int core_scsi3_update_and_write_aptpl(struct se_device *dev, bool aptpl) 1959 + static sense_reason_t core_scsi3_update_and_write_aptpl(struct se_device *dev, bool aptpl) 1960 1960 { 1961 - int ret = 0; 1961 + unsigned char *buf; 1962 + int rc; 1962 1963 1963 1964 if (!aptpl) { 1964 1965 char *null_buf = "No Registrations or Reservations\n"; 1965 1966 1966 - ret = __core_scsi3_write_aptpl_to_file(dev, null_buf); 1967 + rc = __core_scsi3_write_aptpl_to_file(dev, null_buf); 1967 1968 dev->t10_pr.pr_aptpl_active = 0; 1968 1969 pr_debug("SPC-3 PR: Set APTPL Bit Deactivated\n"); 1969 - } else { 1970 - int ret; 1971 - unsigned char *buf; 1972 1970 1973 - buf = kzalloc(PR_APTPL_BUF_LEN, GFP_KERNEL); 1974 - if (!buf) 1975 - return -ENOMEM; 1971 + if (rc) 1972 + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 1976 1973 1977 - ret = core_scsi3_update_aptpl_buf(dev, buf, PR_APTPL_BUF_LEN); 1978 - if (ret < 0) { 1979 - kfree(buf); 1980 - return ret; 1981 - } 1982 - 1983 - ret = __core_scsi3_write_aptpl_to_file(dev, buf); 1984 - if (ret != 0) { 1985 - pr_err("SPC-3 PR: Could not update APTPL\n"); 1986 - } else { 1987 - dev->t10_pr.pr_aptpl_active = 1; 1988 - pr_debug("SPC-3 PR: Set APTPL Bit Activated\n"); 1989 - } 1990 - kfree(buf); 1974 + return 0; 1991 1975 } 1992 1976 1993 - return ret; 1977 + buf = kzalloc(PR_APTPL_BUF_LEN, GFP_KERNEL); 1978 + if (!buf) 1979 + return TCM_OUT_OF_RESOURCES; 1980 + 1981 + rc = core_scsi3_update_aptpl_buf(dev, buf, PR_APTPL_BUF_LEN); 1982 + if (rc < 0) { 1983 + kfree(buf); 1984 + return TCM_OUT_OF_RESOURCES; 1985 + } 1986 + 1987 + rc = __core_scsi3_write_aptpl_to_file(dev, buf); 1988 + if (rc != 0) { 1989 + pr_err("SPC-3 PR: Could not update APTPL\n"); 1990 + kfree(buf); 1991 + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 1992 + } 1993 + dev->t10_pr.pr_aptpl_active = 1; 1994 + kfree(buf); 1995 + pr_debug("SPC-3 PR: Set APTPL Bit Activated\n"); 1996 + return 0; 1994 1997 } 1995 1998 1996 1999 static sense_reason_t