[PATCH] scsi: aic7xxx: aic7xxx_core: Remove some unused functions

2015-01-03 Thread Rickard Strandqvist
Removes some functions that are not used anywhere:
ahc_outq() ahc_inq()

This was partially found by using a static code analysis program called 
cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/aic7xxx/aic7xxx_core.c   |   26 --
 drivers/scsi/aic7xxx/aic7xxx_inline.h |4 
 2 files changed, 30 deletions(-)

diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c 
b/drivers/scsi/aic7xxx/aic7xxx_core.c
index 10172a3..6f91465 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_core.c
+++ b/drivers/scsi/aic7xxx/aic7xxx_core.c
@@ -494,32 +494,6 @@ ahc_outl(struct ahc_softc *ahc, u_int port, uint32_t value)
ahc_outb(ahc, port+3, ((value)  24)  0xFF);
 }
 
-uint64_t
-ahc_inq(struct ahc_softc *ahc, u_int port)
-{
-   return ((ahc_inb(ahc, port))
- | (ahc_inb(ahc, port+1)  8)
- | (ahc_inb(ahc, port+2)  16)
- | (ahc_inb(ahc, port+3)  24)
- | (((uint64_t)ahc_inb(ahc, port+4))  32)
- | (((uint64_t)ahc_inb(ahc, port+5))  40)
- | (((uint64_t)ahc_inb(ahc, port+6))  48)
- | (((uint64_t)ahc_inb(ahc, port+7))  56));
-}
-
-void
-ahc_outq(struct ahc_softc *ahc, u_int port, uint64_t value)
-{
-   ahc_outb(ahc, port, value  0xFF);
-   ahc_outb(ahc, port+1, (value  8)  0xFF);
-   ahc_outb(ahc, port+2, (value  16)  0xFF);
-   ahc_outb(ahc, port+3, (value  24)  0xFF);
-   ahc_outb(ahc, port+4, (value  32)  0xFF);
-   ahc_outb(ahc, port+5, (value  40)  0xFF);
-   ahc_outb(ahc, port+6, (value  48)  0xFF);
-   ahc_outb(ahc, port+7, (value  56)  0xFF);
-}
-
 /*
  * Get a free scb. If there are none, see if we can allocate a new SCB.
  */
diff --git a/drivers/scsi/aic7xxx/aic7xxx_inline.h 
b/drivers/scsi/aic7xxx/aic7xxx_inline.h
index 0b57b78..cef8d98 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_inline.h
+++ b/drivers/scsi/aic7xxx/aic7xxx_inline.h
@@ -77,10 +77,6 @@ uint32_t
ahc_inl(struct ahc_softc *ahc, u_int port);
 void   ahc_outl(struct ahc_softc *ahc, u_int port,
 uint32_t value);
-uint64_t
-   ahc_inq(struct ahc_softc *ahc, u_int port);
-void   ahc_outq(struct ahc_softc *ahc, u_int port,
-uint64_t value);
 struct scb*
ahc_get_scb(struct ahc_softc *ahc);
 void   ahc_free_scb(struct ahc_softc *ahc, struct scb *scb);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: aic7xxx: aic7770: Remove unused function

2015-01-02 Thread Rickard Strandqvist
Remove the function aic7770_find_device() that is not used anywhere.

This was partially found by using a static code analysis program called 
cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/aic7xxx/aic7770.c |   14 --
 drivers/scsi/aic7xxx/aic7xxx.h |1 -
 2 files changed, 15 deletions(-)

diff --git a/drivers/scsi/aic7xxx/aic7770.c b/drivers/scsi/aic7xxx/aic7770.c
index 5000bd6..cbe10755 100644
--- a/drivers/scsi/aic7xxx/aic7770.c
+++ b/drivers/scsi/aic7xxx/aic7770.c
@@ -107,20 +107,6 @@ struct aic7770_identity aic7770_ident_table[] =
 };
 const int ahc_num_aic7770_devs = ARRAY_SIZE(aic7770_ident_table);
 
-struct aic7770_identity *
-aic7770_find_device(uint32_t id)
-{
-   struct  aic7770_identity *entry;
-   int i;
-
-   for (i = 0; i  ahc_num_aic7770_devs; i++) {
-   entry = aic7770_ident_table[i];
-   if (entry-full_id == (id  entry-id_mask))
-   return (entry);
-   }
-   return (NULL);
-}
-
 int
 aic7770_config(struct ahc_softc *ahc, struct aic7770_identity *entry, u_int io)
 {
diff --git a/drivers/scsi/aic7xxx/aic7xxx.h b/drivers/scsi/aic7xxx/aic7xxx.h
index f695774..ead8924 100644
--- a/drivers/scsi/aic7xxx/aic7xxx.h
+++ b/drivers/scsi/aic7xxx/aic7xxx.h
@@ -1144,7 +1144,6 @@ void   ahc_pci_resume(struct 
ahc_softc *ahc);
 #endif
 
 /*** EISA/VL Front End 
/
-struct aic7770_identity *aic7770_find_device(uint32_t);
 int aic7770_config(struct ahc_softc *ahc,
struct aic7770_identity *,
u_int port);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: cxgbi: libcxgbi.c: Remove some unused functions

2015-01-01 Thread Rickard Strandqvist
Removes some functions that are not used anywhere:
csk_print_ip() csk_print_port()

This was partially found by using a static code analysis program called 
cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/cxgbi/libcxgbi.c |   28 
 1 file changed, 28 deletions(-)

diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c
index 674d498..7d2884b 100644
--- a/drivers/scsi/cxgbi/libcxgbi.c
+++ b/drivers/scsi/cxgbi/libcxgbi.c
@@ -2434,34 +2434,6 @@ int cxgbi_set_conn_param(struct iscsi_cls_conn *cls_conn,
 }
 EXPORT_SYMBOL_GPL(cxgbi_set_conn_param);
 
-static inline int csk_print_port(struct cxgbi_sock *csk, char *buf)
-{
-   int len;
-
-   cxgbi_sock_get(csk);
-   len = sprintf(buf, %hu\n, ntohs(csk-daddr.sin_port));
-   cxgbi_sock_put(csk);
-
-   return len;
-}
-
-static inline int csk_print_ip(struct cxgbi_sock *csk, char *buf)
-{
-   int len;
-
-   cxgbi_sock_get(csk);
-   if (csk-csk_family == AF_INET)
-   len = sprintf(buf, %pI4,
- csk-daddr.sin_addr.s_addr);
-   else
-   len = sprintf(buf, %pI6,
- csk-daddr6.sin6_addr);
-
-   cxgbi_sock_put(csk);
-
-   return len;
-}
-
 int cxgbi_get_ep_param(struct iscsi_endpoint *ep, enum iscsi_param param,
   char *buf)
 {
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: 3w-9xxx.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-12-22 Thread Rickard Strandqvist
2014-08-01 0:19 GMT+02:00 adam radford aradf...@gmail.com:
 On Sun, Jul 27, 2014 at 8:11 AM, Rickard Strandqvist
 rickard_strandqv...@spectrumdigital.se wrote:
 Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
 And use the sizeof on the to string rather than strlen on the from string.

 Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
 ---
  drivers/scsi/3w-9xxx.c |3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

 diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
 index 0a73253..f4d2331 100644
 --- a/drivers/scsi/3w-9xxx.c
 +++ b/drivers/scsi/3w-9xxx.c
 @@ -621,7 +621,8 @@ static int twa_check_srl(TW_Device_Extension *tw_dev, 
 int *flashed)
 }

 /* Load rest of compatibility struct */
 -   strncpy(tw_dev-tw_compat_info.driver_version, TW_DRIVER_VERSION, 
 strlen(TW_DRIVER_VERSION));
 +   strlcpy(tw_dev-tw_compat_info.driver_version, TW_DRIVER_VERSION,
 +   sizeof(tw_dev-tw_compat_info.driver_version));
 tw_dev-tw_compat_info.driver_srl_high = TW_CURRENT_DRIVER_SRL;
 tw_dev-tw_compat_info.driver_branch_high = TW_CURRENT_DRIVER_BRANCH;
 tw_dev-tw_compat_info.driver_build_high = TW_CURRENT_DRIVER_BUILD;
 --
 1.7.10.4

 --
 To unsubscribe from this list: send the line unsubscribe linux-kernel in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
 Please read the FAQ at  http://www.tux.org/lkml/

 Rickard,

 This patch looks fine.

 Acked-by: Adam Radford aradf...@gmail.com

 -Adam


Hi Adam!

What happened to this patch?


Kind regards
Rickard Strandqvist
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: arm: cumana_1.c: Remove unused function

2014-12-20 Thread Rickard Strandqvist
Remove the function cumanascsi_setup() that is not used anywhere.

This was partially found by using a static code analysis program called 
cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/arm/cumana_1.c |4 
 1 file changed, 4 deletions(-)

diff --git a/drivers/scsi/arm/cumana_1.c b/drivers/scsi/arm/cumana_1.c
index 8ef810a..7c90d9c 100644
--- a/drivers/scsi/arm/cumana_1.c
+++ b/drivers/scsi/arm/cumana_1.c
@@ -38,10 +38,6 @@
 
 #include ../NCR5380.h
 
-void cumanascsi_setup(char *str, int *ints)
-{
-}
-
 const char *cumanascsi_info(struct Scsi_Host *spnt)
 {
return ;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: arm: cumana_1.c: Remove unused function

2014-12-20 Thread Rickard Strandqvist
2014-12-20 17:50 GMT+01:00 Jeremiah Mahler jmmah...@gmail.com:
 On Sat, Dec 20, 2014 at 05:36:15PM +0100, Rickard Strandqvist wrote:
 Remove the function cumanascsi_setup() that is not used anywhere.

 This was partially found by using a static code analysis program called 
 cppcheck.

 Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
 ---
  drivers/scsi/arm/cumana_1.c |4 
  1 file changed, 4 deletions(-)

 diff --git a/drivers/scsi/arm/cumana_1.c b/drivers/scsi/arm/cumana_1.c
 index 8ef810a..7c90d9c 100644
 --- a/drivers/scsi/arm/cumana_1.c
 +++ b/drivers/scsi/arm/cumana_1.c
 @@ -38,10 +38,6 @@

  #include ../NCR5380.h

 -void cumanascsi_setup(char *str, int *ints)
 -{
 -}
 -
  const char *cumanascsi_info(struct Scsi_Host *spnt)
  {
   return ;
 [...]

 You can blame Linus for this one :-)

 ~/linux-next$ git blame -L 38,40 drivers/scsi/arm/cumana_1.c
 ^1da177e (Linus Torvalds 2005-04-16 15:20:36 -0700 38) void
 cumanascsi_setup(char *str, int *ints)
 ^1da177e (Linus Torvalds 2005-04-16 15:20:36 -0700 39) {
 ^1da177e (Linus Torvalds 2005-04-16 15:20:36 -0700 40) }
 ~/linux-next$

 --
 - Jeremiah Mahler



It just shows, Linus!
What he has contributed lately  ;-)

Kind regards
Rickard Strandqvist
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: gdth_proc.c: Remove unused function

2014-12-20 Thread Rickard Strandqvist
Remove the function gdth_ioctl_check_bin() that is not used anywhere.

This was partially found by using a static code analysis program called 
cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/gdth_proc.c |   18 --
 1 file changed, 18 deletions(-)

diff --git a/drivers/scsi/gdth_proc.c b/drivers/scsi/gdth_proc.c
index 9fb6326..efb9df5 100644
--- a/drivers/scsi/gdth_proc.c
+++ b/drivers/scsi/gdth_proc.c
@@ -598,24 +598,6 @@ static void gdth_ioctl_free(gdth_ha_str *ha, int size, 
char *buf, u64 paddr)
 }
 }
 
-#ifdef GDTH_IOCTL_PROC
-static int gdth_ioctl_check_bin(gdth_ha_str *ha, u16 size)
-{
-unsigned long flags;
-int ret_val;
-
-spin_lock_irqsave(ha-smp_lock, flags);
-
-ret_val = FALSE;
-if (ha-scratch_busy) {
-if (((gdth_iord_str *)ha-pscratch)-size == (u32)size)
-ret_val = TRUE;
-}
-spin_unlock_irqrestore(ha-smp_lock, flags);
-return ret_val;
-}
-#endif
-
 static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id)
 {
 unsigned long flags;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: bfa: bfa_fcpim.c: Remove unused function

2014-12-07 Thread Rickard Strandqvist
Remove the function bfa_tskim_iodone() that is not used anywhere.

This was partially found by using a static code analysis program called 
cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bfa/bfa_fcpim.c |9 -
 drivers/scsi/bfa/bfa_fcpim.h |1 -
 2 files changed, 10 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
index d7385d1..ceb18ef 100644
--- a/drivers/scsi/bfa/bfa_fcpim.c
+++ b/drivers/scsi/bfa/bfa_fcpim.c
@@ -3477,15 +3477,6 @@ bfa_tskim_iocdisable_ios(struct bfa_tskim_s *tskim)
 }
 
 /*
- * Notification on completions from related ioim.
- */
-void
-bfa_tskim_iodone(struct bfa_tskim_s *tskim)
-{
-   bfa_wc_down(tskim-wc);
-}
-
-/*
  * Handle IOC h/w failure notification from itnim.
  */
 void
diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
index e693af6..8ab548f 100644
--- a/drivers/scsi/bfa/bfa_fcpim.h
+++ b/drivers/scsi/bfa/bfa_fcpim.h
@@ -286,7 +286,6 @@ voidbfa_ioim_tov(struct bfa_ioim_s *ioim);
 
 void   bfa_tskim_attach(struct bfa_fcpim_s *fcpim);
 void   bfa_tskim_isr(struct bfa_s *bfa, struct bfi_msg_s *msg);
-void   bfa_tskim_iodone(struct bfa_tskim_s *tskim);
 void   bfa_tskim_iocdisable(struct bfa_tskim_s *tskim);
 void   bfa_tskim_cleanup(struct bfa_tskim_s *tskim);
 void   bfa_tskim_res_recfg(struct bfa_s *bfa, u16 num_tskim_fw);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: bfa: bfa_fcbuild.c: Remove some unused functions

2014-12-07 Thread Rickard Strandqvist
Removes some functions that are not used anywhere:
fc_tprlo_rsp_parse() fc_tprlo_build() fc_prlo_rsp_parse() fc_prlo_build()
fc_pdisc_rsp_parse() fc_pdisc_build() fc_logo_rsp_parse() fc_rpsc_build()
fc_rnid_build() fc_tprlo_acc_build() fc_logout_params_pages() fc_rrq_build()
fc_abts_rsp_parse() fc_abts_build() fc_pdisc_parse() fc_adisc_parse()
fc_prli_parse() fc_plogi_rsp_parse() fc_fdisc_build() fc_flogi_build()
fc_els_rsp_parse() fc_ganxt_build() fc_rptid_build() fc_rcsid_build()
fc_rpnid_build() fc_rftid_build_sol() fc_rscn_build() fc_ct_rsp_parse()
fc_gnnid_build() fc_ba_rjt_build() fc_rrq_rsp_parse()

This was partially found by using a static code analysis program called 
cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bfa/bfa_fcbuild.c |  607 
 drivers/scsi/bfa/bfa_fcbuild.h |   87 --
 2 files changed, 694 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_fcbuild.c b/drivers/scsi/bfa/bfa_fcbuild.c
index dce787f..300264f 100644
--- a/drivers/scsi/bfa/bfa_fcbuild.c
+++ b/drivers/scsi/bfa/bfa_fcbuild.c
@@ -189,27 +189,6 @@ fc_els_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, 
__be16 ox_id)
fchs-ox_id = ox_id;
 }
 
-enum fc_parse_status
-fc_els_rsp_parse(struct fchs_s *fchs, int len)
-{
-   struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
-   struct fc_ls_rjt_s *ls_rjt = (struct fc_ls_rjt_s *) els_cmd;
-
-   len = len;
-
-   switch (els_cmd-els_code) {
-   case FC_ELS_LS_RJT:
-   if (ls_rjt-reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY)
-   return FC_PARSE_BUSY;
-   else
-   return FC_PARSE_FAILURE;
-
-   case FC_ELS_ACC:
-   return FC_PARSE_OK;
-   }
-   return FC_PARSE_OK;
-}
-
 static void
 fc_bls_rsp_build(struct fchs_s *fchs, u32 d_id, u32 s_id, __be16 ox_id)
 {
@@ -248,44 +227,6 @@ fc_plogi_x_build(struct fchs_s *fchs, void *pld, u32 d_id, 
u32 s_id,
 }
 
 u16
-fc_flogi_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
-   u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size,
-  u8 set_npiv, u8 set_auth, u16 local_bb_credits)
-{
-   u32d_id = bfa_hton3b(FC_FABRIC_PORT);
-   __be32  *vvl_info;
-
-   memcpy(flogi, plogi_tmpl, sizeof(struct fc_logi_s));
-
-   flogi-els_cmd.els_code = FC_ELS_FLOGI;
-   fc_els_req_build(fchs, d_id, s_id, ox_id);
-
-   flogi-csp.rxsz = flogi-class3.rxsz = cpu_to_be16(pdu_size);
-   flogi-port_name = port_name;
-   flogi-node_name = node_name;
-
-   /*
-* Set the NPIV Capability Bit ( word 1, bit 31) of Common
-* Service Parameters.
-*/
-   flogi-csp.ciro = set_npiv;
-
-   /* set AUTH capability */
-   flogi-csp.security = set_auth;
-
-   flogi-csp.bbcred = cpu_to_be16(local_bb_credits);
-
-   /* Set brcd token in VVL */
-   vvl_info = (u32 *)flogi-vvl[0];
-
-   /* set the flag to indicate the presence of VVL */
-   flogi-csp.npiv_supp= 1; /* @todo. field name is not correct */
-   vvl_info[0] = cpu_to_be32(FLOGI_VVL_BRCD);
-
-   return sizeof(struct fc_logi_s);
-}
-
-u16
 fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
   __be16 ox_id, wwn_t port_name, wwn_t node_name,
   u16 pdu_size, u16 local_bb_credits, u8 bb_scn)
@@ -308,24 +249,6 @@ fc_flogi_acc_build(struct fchs_s *fchs, struct fc_logi_s 
*flogi, u32 s_id,
 }
 
 u16
-fc_fdisc_build(struct fchs_s *fchs, struct fc_logi_s *flogi, u32 s_id,
-   u16 ox_id, wwn_t port_name, wwn_t node_name, u16 pdu_size)
-{
-   u32d_id = bfa_hton3b(FC_FABRIC_PORT);
-
-   memcpy(flogi, plogi_tmpl, sizeof(struct fc_logi_s));
-
-   flogi-els_cmd.els_code = FC_ELS_FDISC;
-   fc_els_req_build(fchs, d_id, s_id, ox_id);
-
-   flogi-csp.rxsz = flogi-class3.rxsz = cpu_to_be16(pdu_size);
-   flogi-port_name = port_name;
-   flogi-node_name = node_name;
-
-   return sizeof(struct fc_logi_s);
-}
-
-u16
 fc_plogi_build(struct fchs_s *fchs, void *pld, u32 d_id, u32 s_id,
   u16 ox_id, wwn_t port_name, wwn_t node_name,
   u16 pdu_size, u16 bb_cr)
@@ -344,40 +267,6 @@ fc_plogi_acc_build(struct fchs_s *fchs, void *pld, u32 
d_id, u32 s_id,
 }
 
 enum fc_parse_status
-fc_plogi_rsp_parse(struct fchs_s *fchs, int len, wwn_t port_name)
-{
-   struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
-   struct fc_logi_s *plogi;
-   struct fc_ls_rjt_s *ls_rjt;
-
-   switch (els_cmd-els_code) {
-   case FC_ELS_LS_RJT:
-   ls_rjt = (struct fc_ls_rjt_s *) (fchs + 1);
-   if (ls_rjt-reason_code == FC_LS_RJT_RSN_LOGICAL_BUSY)
-   return FC_PARSE_BUSY;
-   else
-   return FC_PARSE_FAILURE;
-   case FC_ELS_ACC:
-   plogi = (struct

[PATCH] scsi: bfa: bfad.c: Remove unused function

2014-12-07 Thread Rickard Strandqvist
Remove the function bfad_drv_uninit() that is not used anywhere.

This was partially found by using a static code analysis program called 
cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bfa/bfad.c |   20 
 drivers/scsi/bfa/bfad_drv.h |1 -
 2 files changed, 21 deletions(-)

diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
index e90a374..336a857 100644
--- a/drivers/scsi/bfa/bfad.c
+++ b/drivers/scsi/bfa/bfad.c
@@ -865,26 +865,6 @@ bfad_drv_init(struct bfad_s *bfad)
 }
 
 void
-bfad_drv_uninit(struct bfad_s *bfad)
-{
-   unsigned long   flags;
-
-   spin_lock_irqsave(bfad-bfad_lock, flags);
-   init_completion(bfad-comp);
-   bfa_iocfc_stop(bfad-bfa);
-   spin_unlock_irqrestore(bfad-bfad_lock, flags);
-   wait_for_completion(bfad-comp);
-
-   del_timer_sync(bfad-hal_tmo);
-   bfa_isr_disable(bfad-bfa);
-   bfa_detach(bfad-bfa);
-   bfad_remove_intr(bfad);
-   bfad_hal_mem_release(bfad);
-
-   bfad-bfad_flags = ~BFAD_DRV_INIT_DONE;
-}
-
-void
 bfad_drv_start(struct bfad_s *bfad)
 {
unsigned long   flags;
diff --git a/drivers/scsi/bfa/bfad_drv.h b/drivers/scsi/bfa/bfad_drv.h
index 8b97877..659132b 100644
--- a/drivers/scsi/bfa/bfad_drv.h
+++ b/drivers/scsi/bfa/bfad_drv.h
@@ -317,7 +317,6 @@ voidbfad_bfa_tmo(unsigned long data);
 void   bfad_init_timer(struct bfad_s *bfad);
 intbfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad);
 void   bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad);
-void   bfad_drv_uninit(struct bfad_s *bfad);
 intbfad_worker(void *ptr);
 void   bfad_debugfs_init(struct bfad_port_s *port);
 void   bfad_debugfs_exit(struct bfad_port_s *port);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/5] scsi: bfa: bfa_fcs_lport.c: Cleaning up missing null-terminate by switching from strncpy to strzcpy

2014-10-20 Thread Rickard Strandqvist
2014-10-20 17:37 GMT+02:00 Dan Carpenter dan.carpen...@oracle.com:
 On Sun, Oct 19, 2014 at 12:13:10AM +0200, Rickard Strandqvist wrote:
 Ensures that the string is null-terminate in connection with the
 use of strncpy, by switching from strncpy to strzcpy.


 I wish the changelogs were more clear that we have no reason to think
 this is a real issue.

 Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
 ---
  drivers/scsi/bfa/bfa_fcs_lport.c |2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c 
 b/drivers/scsi/bfa/bfa_fcs_lport.c
 index ff75ef8..78af89e 100644
 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
 @@ -2633,7 +2633,7 @@ bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s 
 *fdmi,
   strncpy(hba_attr-driver_version, (char *)driver_info-version,
   sizeof(hba_attr-driver_version));

 Why do we not change this one?


 - strncpy(hba_attr-os_name, driver_info-host_os_name,
 + strzcpy(hba_attr-os_name, driver_info-host_os_name,
   sizeof(hba_attr-os_name));

 strlcpy() would also be totally safe here.  It's also safe for patch
 patch 3 and patch 4.  Patch 5 is trickier to audit so I don't know if
 strlcpy() is safe.


Hi Dan

It was a miss, should have done this on both strncpy.

After becoming quite attacked for having changed to strlcpy I am very
careful with it now.
But ok, then I submit 2 3 4 with strlcpy instead.

But this is a little bad example for strzcpy though :-(

Kind regards
Rickard Strandqvist
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/5] scsi: bfa: bfa_fcs_lport.c: Cleaning up missing null-terminate by switching from strncpy to strzcpy

2014-10-18 Thread Rickard Strandqvist
Ensures that the string is null-terminate in connection with the
use of strncpy, by switching from strncpy to strzcpy.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bfa/bfa_fcs_lport.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
index ff75ef8..78af89e 100644
--- a/drivers/scsi/bfa/bfa_fcs_lport.c
+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
@@ -2633,7 +2633,7 @@ bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s 
*fdmi,
strncpy(hba_attr-driver_version, (char *)driver_info-version,
sizeof(hba_attr-driver_version));
 
-   strncpy(hba_attr-os_name, driver_info-host_os_name,
+   strzcpy(hba_attr-os_name, driver_info-host_os_name,
sizeof(hba_attr-os_name));
 
/*
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] target: iscsi: iscsi_target_tpg.c: Cleaning up possible size overwriting in conjunction with sprintf

2014-10-12 Thread Rickard Strandqvist
2014-10-12 20:18 GMT+02:00 Joe Perches j...@perches.com:
 On Sun, 2014-10-12 at 19:55 +0200, Rickard Strandqvist wrote:
 Changed same snprintf and sprintf to strlcpy and strlcat.
 This will guarantee that the string size is not overwritten,
 and they are significantly faster than sprintf also.

 I don't disagree with the change, but I think the changelog is
 misleading.

 strlcpy(ptr, ...) then strlcat(ptr, ...) does not use the known
 length of the first copied string and is generally not faster than
 ptr += snprintf(ptr, ...) then sprintf(ptr,...)

 And a couple slightly unrelated bits:

 diff --git a/drivers/target/iscsi/iscsi_target_tpg.c 
 b/drivers/target/iscsi/iscsi_target_tpg.c
 index c3cb5c1..6fc8bfe 100644
 --- a/drivers/target/iscsi/iscsi_target_tpg.c
 +++ b/drivers/target/iscsi/iscsi_target_tpg.c
 @@ -608,7 +608,6 @@ int iscsit_tpg_set_initiator_node_queue_depth(
  int iscsit_ta_authentication(struct iscsi_portal_group *tpg, u32 
 authentication)

 This function could be made static and the prototype removed from
 the .h file if it is moved above its one caller in this file.

  {
   unsigned char buf1[256], buf2[256], *none = NULL;

 Moderately large stack use here.




Hi

Can not agree with you about speed.
But regardless of that, it is ironically precisely the behavior you
describe that is a part of the problem.
Form the man page for snprintf
If the output was truncated due to this limit then the return value
is the number of characters (excluding the terminating null byte)
which would have been written to the final string if enough space had
been available

Switching to static funktion sounds good.
And less use of static memory, anyone have a more reasonable idea of a size?


Kind regards
Rickard Strandqvist
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: scsi_devinfo.c: Cleaning up unnecessarily complicated in conjunction with strncpy

2014-09-15 Thread Rickard Strandqvist
2014-09-15 0:38 GMT+02:00 Elliott, Robert (Server Storage) elli...@hp.com:


 -Original Message-
 From: Rickard Strandqvist [mailto:rickard_strandqv...@spectrumdigital.se]
 How do you mean?

 strncpy zeroes throughout the remainder of the string from until the
 length off to_length, or otherwise guaranteed trailing zero characters
 and a warning is printed.

 Is not it exactly the functionality that is desired?

 Ah, I see that in man 3 strcpy:
 If the length of src is less than n, strncpy() pads the
  remainder of dest with null bytes.

 I agree that should work.

 ---
 Rob ElliottHP Server Storage


Hi

Okay, good.
Suspected that there was some misunderstanding :)

Kind regards
Rickard Strandqvist
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: scsi_devinfo.c: Cleaning up unnecessarily complicated in conjunction with strncpy

2014-09-14 Thread Rickard Strandqvist
I have revamped the code so it becomes both more effective and far more clear.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/scsi_devinfo.c |   31 +++
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
index 49014a1..f6752cc 100644
--- a/drivers/scsi/scsi_devinfo.c
+++ b/drivers/scsi/scsi_devinfo.c
@@ -282,27 +282,18 @@ static struct scsi_dev_info_list_table 
*scsi_devinfo_lookup_by_key(int key)
 static void scsi_strcpy_devinfo(char *name, char *to, size_t to_length,
char *from, int compatible)
 {
-   size_t from_length;
-
-   from_length = strlen(from);
-   strncpy(to, from, min(to_length, from_length));
-   if (from_length  to_length) {
-   if (compatible) {
-   /*
-* NUL terminate the string if it is short.
-*/
-   to[from_length] = '\0';
-   } else {
-   /* 
-* space pad the string if it is short. 
-*/
-   strncpy(to[from_length], spaces,
-   to_length - from_length);
-   }
-   }
-   if (from_length  to_length)
-printk(KERN_WARNING %s: %s string '%s' is too long\n,
+   strncpy(to, from, to_length);
+   if (to[to_length - 1] != '\0') {
+   to[to_length - 1] = '\0';
+   printk(KERN_WARNING %s: %s string '%s' is too long\n,
__func__, name, from);
+   }
+   if (!compatible) {
+   /*
+* space pad the string if it is short.
+*/
+   strlcat(to, spaces, to_length);
+   }
 }
 
 /**
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: scsi_devinfo.c: Cleaning up unnecessarily complicated in conjunction with strncpy

2014-09-14 Thread Rickard Strandqvist
2014-09-14 23:34 GMT+02:00 Elliott, Robert (Server Storage) elli...@hp.com:


 -Original Message-
 From: linux-scsi-ow...@vger.kernel.org [mailto:linux-scsi-
 ow...@vger.kernel.org] On Behalf Of Rickard Strandqvist
 ...
 diff --git a/drivers/scsi/scsi_devinfo.c b/drivers/scsi/scsi_devinfo.c
 ...
  static void scsi_strcpy_devinfo(char *name, char *to, size_t to_length,
   char *from, int compatible)
  {
 - size_t from_length;
 -
 - from_length = strlen(from);
 - strncpy(to, from, min(to_length, from_length));
 - if (from_length  to_length) {
 - if (compatible) {
 - /*
 -  * NUL terminate the string if it is short.
 -  */
 - to[from_length] = '\0';
 - } else {
 - /*
 -  * space pad the string if it is short.
 -  */
 - strncpy(to[from_length], spaces,
 - to_length - from_length);
 - }
 - }
 - if (from_length  to_length)
 -  printk(KERN_WARNING %s: %s string '%s' is too long\n,
 + strncpy(to, from, to_length);
 + if (to[to_length - 1] != '\0') {
 + to[to_length - 1] = '\0';
 + printk(KERN_WARNING %s: %s string '%s' is too long\n,
   __func__, name, from);
 + }

 The caller of this function, scsi_dev_info_list_add_keyed, created
 the to destination buffer, devinfo, with kmalloc, so it's not
 guaranteed to be full of zeros.

 If from_length is shorter than to_length, then this code will
 be inspecting an uninitialized character that strncpy didn't
 touch.

 ---
 Rob ElliottHP Server Storage


Hi Elliott

How do you mean?

strncpy zeroes throughout the remainder of the string from until the
length off to_length, or otherwise guaranteed trailing zero characters
and a warning is printed.

Is not it exactly the functionality that is desired?

Kind regards
Rickard Strandqvist
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] message: fusion: mptbase.c: Cleaning up missing null-terminate after strncpy call

2014-08-09 Thread Rickard Strandqvist
Added a guaranteed null-terminate after call to strncpy.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/message/fusion/mptbase.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index ebc0af7..66324f8 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -7706,8 +7706,10 @@ mpt_display_event_info(MPT_ADAPTER *ioc, 
EventNotificationReply_t *pEventReply)
ds = Unknown;
break;
}
-   if (ds)
+   if (ds) {
strncpy(evStr, ds, EVENT_DESCR_STR_SZ);
+   evStr[EVENT_DESCR_STR_SZ - 1] = '\0';
+   }
 
 
devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: ibmvscsi: ibmvstgt.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-08-02 Thread Rickard Strandqvist
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/ibmvscsi/ibmvstgt.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/ibmvscsi/ibmvstgt.c b/drivers/scsi/ibmvscsi/ibmvstgt.c
index 56f8a86..5c16d17 100644
--- a/drivers/scsi/ibmvscsi/ibmvstgt.c
+++ b/drivers/scsi/ibmvscsi/ibmvstgt.c
@@ -340,7 +340,7 @@ int send_adapter_info(struct iu_entry *iue,
memset(info, 0, sizeof(*info));
 
strcpy(info-srp_version, 16.a);
-   strncpy(info-partition_name, partition_name,
+   strlcpy(info-partition_name, partition_name,
sizeof(info-partition_name));
info-partition_number = partition_number;
info-mad_version = 1;
@@ -938,7 +938,7 @@ static int get_system_info(void)
 
name = of_get_property(rootdn, ibm,partition-name, NULL);
if (name)
-   strncpy(partition_name, name, sizeof(partition_name));
+   strlcpy(partition_name, name, sizeof(partition_name));
 
num = of_get_property(rootdn, ibm,partition-no, NULL);
if (num)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: ch.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-30 Thread Rickard Strandqvist
If you are going to use memset before strncpy you must copy sizeof -1.
And removed unnecessary magic numbers.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/ch.c |   12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index 2a32374..1fecf60 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -634,19 +634,23 @@ static long ch_ioctl(struct file *file,
memset(vparams,0,sizeof(vparams));
if (ch-counts[CHET_V1]) {
vparams.cvp_n1  = ch-counts[CHET_V1];
-   strncpy(vparams.cvp_label1,vendor_labels[0],16);
+   strncpy(vparams.cvp_label1, vendor_labels[0],
+   sizeof(vparams.cvp_label1) - 1);
}
if (ch-counts[CHET_V2]) {
vparams.cvp_n2  = ch-counts[CHET_V2];
-   strncpy(vparams.cvp_label2,vendor_labels[1],16);
+   strncpy(vparams.cvp_label2, vendor_labels[1],
+   sizeof(vparams.cvp_label2) - 1);
}
if (ch-counts[CHET_V3]) {
vparams.cvp_n3  = ch-counts[CHET_V3];
-   strncpy(vparams.cvp_label3,vendor_labels[2],16);
+   strncpy(vparams.cvp_label3, vendor_labels[2],
+   sizeof(vparams.cvp_label3) - 1);
}
if (ch-counts[CHET_V4]) {
vparams.cvp_n4  = ch-counts[CHET_V4];
-   strncpy(vparams.cvp_label4,vendor_labels[3],16);
+   strncpy(vparams.cvp_label4, vendor_labels[3],
+   sizeof(vparams.cvp_label4) - 1);
}
if (copy_to_user(argp, vparams, sizeof(vparams)))
return -EFAULT;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: csiostor: csio_init.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-30 Thread Rickard Strandqvist
If you use kzalloc before strncpy you must copy sizeof -1.
And removed unnecessary magic numbers.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/csiostor/csio_init.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/csiostor/csio_init.c 
b/drivers/scsi/csiostor/csio_init.c
index 1aafc33..d5ea81c 100644
--- a/drivers/scsi/csiostor/csio_init.c
+++ b/drivers/scsi/csiostor/csio_init.c
@@ -532,7 +532,8 @@ static struct csio_hw *csio_hw_alloc(struct pci_dev *pdev)
goto err;
 
hw-pdev = pdev;
-   strncpy(hw-drv_version, CSIO_DRV_VERSION, 32);
+   strncpy(hw-drv_version, CSIO_DRV_VERSION,
+   sizeof(hw-drv_version) - 1);
 
/* memory pool/DMA pool allocation */
if (csio_resource_alloc(hw))
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: hpsa.c: Cleaning up code clarification using strlcpy

2014-07-30 Thread Rickard Strandqvist
Code clarification using strlcpy instead of strncpy.
And removed unnecessary memset

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/hpsa.c |   16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 31184b3..814d64d 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -315,16 +315,15 @@ static ssize_t host_store_hp_ssd_smart_path_status(struct 
device *dev,
 struct device_attribute *attr,
 const char *buf, size_t count)
 {
-   int status, len;
+   int status;
struct ctlr_info *h;
struct Scsi_Host *shost = class_to_shost(dev);
char tmpbuf[10];
 
if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
return -EACCES;
-   len = count  sizeof(tmpbuf) - 1 ? sizeof(tmpbuf) - 1 : count;
-   strncpy(tmpbuf, buf, len);
-   tmpbuf[len] = '\0';
+   strlcpy(tmpbuf, buf,
+   count  sizeof(tmpbuf) ? sizeof(tmpbuf) : count);
if (sscanf(tmpbuf, %d, status) != 1)
return -EINVAL;
h = shost_to_hba(shost);
@@ -339,16 +338,15 @@ static ssize_t host_store_raid_offload_debug(struct 
device *dev,
 struct device_attribute *attr,
 const char *buf, size_t count)
 {
-   int debug_level, len;
+   int debug_level;
struct ctlr_info *h;
struct Scsi_Host *shost = class_to_shost(dev);
char tmpbuf[10];
 
if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
return -EACCES;
-   len = count  sizeof(tmpbuf) - 1 ? sizeof(tmpbuf) - 1 : count;
-   strncpy(tmpbuf, buf, len);
-   tmpbuf[len] = '\0';
+   strlcpy(tmpbuf, buf,
+   count  sizeof(tmpbuf) ? sizeof(tmpbuf) : count);
if (sscanf(tmpbuf, %d, debug_level) != 1)
return -EINVAL;
if (debug_level  0)
@@ -5881,8 +5879,8 @@ static int hpsa_controller_hard_reset(struct pci_dev 
*pdev,
 
 static void init_driver_version(char *driver_version, int len)
 {
-   memset(driver_version, 0, len);
strncpy(driver_version, HPSA   HPSA_DRIVER_VERSION, len - 1);
+   driver_version[len - 1] = '\0';
 }
 
 static int write_driver_ver_to_cfgtable(struct CfgTable __iomem *cfgtable)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: ibmvscsi: ibmvfc.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-30 Thread Rickard Strandqvist
And as I understand it, it is fine to replace strncpy to strlcpy here.
But if any of this code do not want a null terminated, or want to have the 
whole rest of size filled with null characters. 
If that is the case this is not a good patch.

Rickard Strandqvist (1):
  scsi: ibmvscsi: ibmvfc.c:  Cleaning up missing null-terminate in conjunction 
with
strncpy

 drivers/scsi/ibmvscsi/ibmvfc.c |   10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: ibmvscsi: ibmvfc.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-30 Thread Rickard Strandqvist
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/ibmvscsi/ibmvfc.c |   10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/ibmvscsi/ibmvfc.c b/drivers/scsi/ibmvscsi/ibmvfc.c
index 8dd4768..56c26ef 100644
--- a/drivers/scsi/ibmvscsi/ibmvfc.c
+++ b/drivers/scsi/ibmvscsi/ibmvfc.c
@@ -1149,7 +1149,8 @@ static void ibmvfc_gather_partition_info(struct 
ibmvfc_host *vhost)
 
name = of_get_property(rootdn, ibm,partition-name, NULL);
if (name)
-   strncpy(vhost-partition_name, name, 
sizeof(vhost-partition_name));
+   strlcpy(vhost-partition_name, name,
+   sizeof(vhost-partition_name));
num = of_get_property(rootdn, ibm,partition-no, NULL);
if (num)
vhost-partition_number = *num;
@@ -1186,13 +1187,14 @@ static void ibmvfc_set_login_info(struct ibmvfc_host 
*vhost)
login_info-capabilities = IBMVFC_CAN_MIGRATE;
login_info-async.va = vhost-async_crq.msg_token;
login_info-async.len = vhost-async_crq.size * 
sizeof(*vhost-async_crq.msgs);
-   strncpy(login_info-partition_name, vhost-partition_name, 
IBMVFC_MAX_NAME);
-   strncpy(login_info-device_name,
+   strlcpy(login_info-partition_name, vhost-partition_name,
+   IBMVFC_MAX_NAME);
+   strlcpy(login_info-device_name,
dev_name(vhost-host-shost_gendev), IBMVFC_MAX_NAME);
 
location = of_get_property(of_node, ibm,loc-code, NULL);
location = location ? location : dev_name(vhost-dev);
-   strncpy(login_info-drc_name, location, IBMVFC_MAX_NAME);
+   strlcpy(login_info-drc_name, location, IBMVFC_MAX_NAME);
 }
 
 /**
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] block: bsg.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-29 Thread Rickard Strandqvist
2014-07-28 16:31 GMT+02:00 Jeff Moyer jmo...@redhat.com:
 Rickard Strandqvist rickard_strandqv...@spectrumdigital.se writes:

 Replacing strncpy with strlcpy to avoid strings that lacks null terminate.

 Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
 ---
  block/bsg.c |2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

 diff --git a/block/bsg.c b/block/bsg.c
 index ff46add..b2688c5 100644
 --- a/block/bsg.c
 +++ b/block/bsg.c
 @@ -790,7 +790,7 @@ static struct bsg_device *bsg_add_device(struct inode 
 *inode,
   mutex_lock(bsg_mutex);
   hlist_add_head(bd-dev_list, bsg_dev_idx_hash(iminor(inode)));

 - strncpy(bd-name, dev_name(rq-bsg_dev.class_dev), sizeof(bd-name) - 
 1);
 + strlcpy(bd-name, dev_name(rq-bsg_dev.class_dev), sizeof(bd-name));
   dprintk(bound to %s, max queue %d\n,
   format_dev_t(buf, inode-i_rdev), bd-max_queue);

 NACK

 The bsg data structure is allocated using kzalloc, so that last byte
 will be zero.

Hi

Sorry.. I did not know bsg_alloc_device used kzalloc, right then
everything should be ok.

Kind regards
Rickard Strandqvist
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: qla4xxx: ql4_mbx.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-27 Thread Rickard Strandqvist
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
And in some cases modified to copy one character less than the overall
length, as the entire area is already zeroed.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/qla4xxx/ql4_mbx.c |   14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/qla4xxx/ql4_mbx.c b/drivers/scsi/qla4xxx/ql4_mbx.c
index 0a3312c..2b2756e 100644
--- a/drivers/scsi/qla4xxx/ql4_mbx.c
+++ b/drivers/scsi/qla4xxx/ql4_mbx.c
@@ -1620,8 +1620,8 @@ int qla4xxx_get_chap(struct scsi_qla_host *ha, char 
*username, char *password,
goto exit_get_chap;
}
 
-   strncpy(password, chap_table-secret, QL4_CHAP_MAX_SECRET_LEN);
-   strncpy(username, chap_table-name, QL4_CHAP_MAX_NAME_LEN);
+   strlcpy(password, chap_table-secret, QL4_CHAP_MAX_SECRET_LEN);
+   strlcpy(username, chap_table-name, QL4_CHAP_MAX_NAME_LEN);
chap_table-cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
 
 exit_get_chap:
@@ -1663,8 +1663,8 @@ int qla4xxx_set_chap(struct scsi_qla_host *ha, char 
*username, char *password,
else
chap_table-flags |= BIT_7; /* local */
chap_table-secret_len = strlen(password);
-   strncpy(chap_table-secret, password, MAX_CHAP_SECRET_LEN);
-   strncpy(chap_table-name, username, MAX_CHAP_NAME_LEN);
+   strncpy(chap_table-secret, password, MAX_CHAP_SECRET_LEN - 1);
+   strncpy(chap_table-name, username, MAX_CHAP_NAME_LEN - 1);
chap_table-cookie = __constant_cpu_to_le16(CHAP_VALID_COOKIE);
 
if (is_qla40XX(ha)) {
@@ -1742,8 +1742,8 @@ int qla4xxx_get_uni_chap_at_index(struct scsi_qla_host 
*ha, char *username,
goto exit_unlock_uni_chap;
}
 
-   strncpy(password, chap_table-secret, MAX_CHAP_SECRET_LEN);
-   strncpy(username, chap_table-name, MAX_CHAP_NAME_LEN);
+   strlcpy(password, chap_table-secret, MAX_CHAP_SECRET_LEN);
+   strlcpy(username, chap_table-name, MAX_CHAP_NAME_LEN);
 
rval = QLA_SUCCESS;
 
@@ -2295,7 +2295,7 @@ int qla4_8xxx_set_param(struct scsi_qla_host *ha, int 
param)
if (param == SET_DRVR_VERSION) {
mbox_cmd[1] = SET_DRVR_VERSION;
strncpy((char *)mbox_cmd[2], QLA4XXX_DRIVER_VERSION,
-   MAX_DRVR_VER_LEN);
+   MAX_DRVR_VER_LEN - 1);
} else {
ql4_printk(KERN_ERR, ha, %s: invalid parameter 0x%x\n,
   __func__, param);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: 3w-9xxx.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-27 Thread Rickard Strandqvist
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
And use the sizeof on the to string rather than strlen on the from string.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/3w-9xxx.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 0a73253..f4d2331 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -621,7 +621,8 @@ static int twa_check_srl(TW_Device_Extension *tw_dev, int 
*flashed)
}
 
/* Load rest of compatibility struct */
-   strncpy(tw_dev-tw_compat_info.driver_version, TW_DRIVER_VERSION, 
strlen(TW_DRIVER_VERSION));
+   strlcpy(tw_dev-tw_compat_info.driver_version, TW_DRIVER_VERSION,
+   sizeof(tw_dev-tw_compat_info.driver_version));
tw_dev-tw_compat_info.driver_srl_high = TW_CURRENT_DRIVER_SRL;
tw_dev-tw_compat_info.driver_branch_high = TW_CURRENT_DRIVER_BRANCH;
tw_dev-tw_compat_info.driver_build_high = TW_CURRENT_DRIVER_BUILD;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: bfa: bfa_fcbuild.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-27 Thread Rickard Strandqvist
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
And use the sizeof on the to string rather than strlen on the from string.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bfa/bfa_fcbuild.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_fcbuild.c b/drivers/scsi/bfa/bfa_fcbuild.c
index dce787f..9294c14 100644
--- a/drivers/scsi/bfa/bfa_fcbuild.c
+++ b/drivers/scsi/bfa/bfa_fcbuild.c
@@ -1249,8 +1249,8 @@ fc_rspnid_build(struct fchs_s *fchs, void *pyld, u32 
s_id, u16 ox_id,
memset(rspnid, 0, sizeof(struct fcgs_rspnid_req_s));
 
rspnid-dap = s_id;
-   rspnid-spn_len = (u8) strlen((char *)name);
-   strncpy((char *)rspnid-spn, (char *)name, rspnid-spn_len);
+   strlcpy((char *)rspnid-spn, (char *)name, sizeof(rspnid-spn));
+   rspnid-spn_len = (u8) strlen((char *)rspnid-spn);
 
return sizeof(struct fcgs_rspnid_req_s) + sizeof(struct ct_hdr_s);
 }
@@ -1270,8 +1270,8 @@ fc_rsnn_nn_build(struct fchs_s *fchs, void *pyld, u32 
s_id,
memset(rsnn_nn, 0, sizeof(struct fcgs_rsnn_nn_req_s));
 
rsnn_nn-node_name = node_name;
-   rsnn_nn-snn_len = (u8) strlen((char *)name);
-   strncpy((char *)rsnn_nn-snn, (char *)name, rsnn_nn-snn_len);
+   strlcpy((char *)rsnn_nn-snn, (char *)name, sizeof(rsnn_nn-snn));
+   rsnn_nn-snn_len = (u8) strlen((char *)rsnn_nn-snn);
 
return sizeof(struct fcgs_rsnn_nn_req_s) + sizeof(struct ct_hdr_s);
 }
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: bfa: bfa_fcs_lport.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-27 Thread Rickard Strandqvist
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
In some cases modified to copy one character less than the overall
length, as the entire area is already zeroed. And replacing strncat
with strlcat because of incorrect use.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bfa/bfa_fcs_lport.c |   47 +++---
 1 file changed, 19 insertions(+), 28 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
index ff75ef8..89e97ee 100644
--- a/drivers/scsi/bfa/bfa_fcs_lport.c
+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
@@ -2631,10 +2631,10 @@ bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s 
*fdmi,
hba_attr-fw_version);
 
strncpy(hba_attr-driver_version, (char *)driver_info-version,
-   sizeof(hba_attr-driver_version));
+   sizeof(hba_attr-driver_version) - 1);
 
strncpy(hba_attr-os_name, driver_info-host_os_name,
-   sizeof(hba_attr-os_name));
+   sizeof(hba_attr-os_name) - 1);
 
/*
 * If there is a patch level, append it
@@ -2652,12 +2652,13 @@ bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s 
*fdmi,
hba_attr-max_ct_pyld = fcs_port_attr.max_frm_size;
 
strncpy(hba_attr-node_sym_name.symname,
-   port-port_cfg.node_sym_name.symname, BFA_SYMNAME_MAXLEN);
+   port-port_cfg.node_sym_name.symname, BFA_SYMNAME_MAXLEN - 1);
strcpy(hba_attr-vendor_info, BROCADE);
hba_attr-num_ports =
cpu_to_be32(bfa_ioc_get_nports(port-fcs-bfa-ioc));
hba_attr-fabric_name = port-fabric-lps-pr_nwwn;
-   strncpy(hba_attr-bios_ver, hba_attr-option_rom_ver, BFA_VERSION_LEN);
+   strncpy(hba_attr-bios_ver, hba_attr-option_rom_ver,
+   BFA_VERSION_LEN - 1);
 
 }
 
@@ -2725,19 +2726,20 @@ bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s 
*fdmi,
 * OS device Name
 */
strncpy(port_attr-os_device_name, (char *)driver_info-os_device_name,
-   sizeof(port_attr-os_device_name));
+   sizeof(port_attr-os_device_name) - 1);
 
/*
 * Host name
 */
strncpy(port_attr-host_name, (char *)driver_info-host_machine_name,
-   sizeof(port_attr-host_name));
+   sizeof(port_attr-host_name) - 1);
 
port_attr-node_name = bfa_fcs_lport_get_nwwn(port);
port_attr-port_name = bfa_fcs_lport_get_pwwn(port);
 
strncpy(port_attr-port_sym_name.symname,
-   (char *)bfa_fcs_lport_get_psym_name(port), BFA_SYMNAME_MAXLEN);
+   (char *)bfa_fcs_lport_get_psym_name(port),
+   BFA_SYMNAME_MAXLEN - 1);
bfa_fcs_lport_get_attr(port, lport_attr);
port_attr-port_type = cpu_to_be32(lport_attr.port_type);
port_attr-scos = pport_attr.cos_supported;
@@ -3217,7 +3219,7 @@ bfa_fcs_lport_ms_gmal_response(void *fcsarg, struct 
bfa_fcxp_s *fcxp,
rsp_str[gmal_entry-len-1] = 0;
 
/* copy IP Address to fabric */
-   strncpy(bfa_fcs_lport_get_fabric_ipaddr(port),
+   strlcpy(bfa_fcs_lport_get_fabric_ipaddr(port),
gmal_entry-ip_addr,
BFA_FCS_FABRIC_IPADDR_SZ);
break;
@@ -4655,21 +4657,15 @@ bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg, struct 
bfa_fcxp_s *fcxp_alloced)
 * to that of the base port.
 */
 
-   strncpy((char *)psymbl,
+   strlcpy((char *)psymbl,
(char *) 
(bfa_fcs_lport_get_psym_name
 (bfa_fcs_get_base_port(port-fcs))),
-   strlen((char *) 
-  bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
- (port-fcs;
-
-   /* Ensure we have a null terminating string. */
-   ((char *)psymbl)[strlen((char *) 
-   bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
-   (port-fcs)))] = 0;
-   strncat((char *)psymbl,
+   sizeof(symbl));
+
+   strlcat((char *)psymbl,
(char *) (bfa_fcs_lport_get_psym_name(port)),
-   strlen((char *) bfa_fcs_lport_get_psym_name(port)));
+   sizeof(symbl));
} else {
psymbl = (u8 *) (bfa_fcs_lport_get_psym_name(port));
}
@@ -5191,18 +5187,13 @@ bfa_fcs_lport_ns_util_send_rspn_id(void *cbarg, struct 
bfa_fcxp_s *fcxp_alloced)
 * For Vports, we append the vport's port symbolic name
 * to that of the base port

[PATCH] scsi: bfa: bfa_fcs.c: Cleaning up missing null-terminate in conjunction with strncpy strncat

2014-07-27 Thread Rickard Strandqvist
Replacing strncp with strlcpy to avoid strings that lacks null terminate.
And strncat with strlcat because of incorrect use,
removed same the duplicated code.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bfa/bfa_fcs.c |   80 ++--
 1 file changed, 33 insertions(+), 47 deletions(-)

diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
index a3ab5cc..48112ee 100644
--- a/drivers/scsi/bfa/bfa_fcs.c
+++ b/drivers/scsi/bfa/bfa_fcs.c
@@ -831,52 +831,41 @@ bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
bfa_ioc_get_adapter_model(fabric-fcs-bfa-ioc, model);
 
/* Model name/number */
-   strncpy((char *)port_cfg-sym_name, model,
-   BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
-   strncat((char *)port_cfg-sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-   sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
+   strlcpy((char *)port_cfg-sym_name, model,
+   BFA_SYMNAME_MAXLEN);
+   strlcat((char *)port_cfg-sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
+   BFA_SYMNAME_MAXLEN);
 
/* Driver Version */
-   strncat((char *)port_cfg-sym_name, (char *)driver_info-version,
-   BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
-   strncat((char *)port_cfg-sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-   sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
+   strlcat((char *)port_cfg-sym_name, (char *)driver_info-version,
+   BFA_SYMNAME_MAXLEN);
+   strlcat((char *)port_cfg-sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
+   BFA_SYMNAME_MAXLEN);
 
/* Host machine name */
-   strncat((char *)port_cfg-sym_name,
+   strlcat((char *)port_cfg-sym_name,
(char *)driver_info-host_machine_name,
-   BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
-   strncat((char *)port_cfg-sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-   sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
+   BFA_SYMNAME_MAXLEN);
+   strlcat((char *)port_cfg-sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
+   BFA_SYMNAME_MAXLEN);
 
/*
 * Host OS Info :
 * If OS Patch Info is not there, do not truncate any bytes from the
 * OS name string and instead copy the entire OS info string (64 bytes).
 */
+   strlcat((char *)port_cfg-sym_name,
+   (char *)driver_info-host_os_name,
+   BFA_SYMNAME_MAXLEN);
+   strlcat((char *)port_cfg-sym_name,
+   BFA_FCS_PORT_SYMBNAME_SEPARATOR,
+   BFA_SYMNAME_MAXLEN);
if (driver_info-host_os_patch[0] == '\0') {
-   strncat((char *)port_cfg-sym_name,
-   (char *)driver_info-host_os_name,
-   BFA_FCS_OS_STR_LEN);
-   strncat((char *)port_cfg-sym_name,
-   BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-   sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
-   } else {
-   strncat((char *)port_cfg-sym_name,
-   (char *)driver_info-host_os_name,
-   BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
-   strncat((char *)port_cfg-sym_name,
-   BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-   sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
-
/* Append host OS Patch Info */
-   strncat((char *)port_cfg-sym_name,
+   strlcat((char *)port_cfg-sym_name,
(char *)driver_info-host_os_patch,
-   BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
+   BFA_SYMNAME_MAXLEN);
}
-
-   /* null terminate */
-   port_cfg-sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
 }
 
 /*
@@ -892,29 +881,26 @@ bfa_fcs_fabric_nsymb_init(struct bfa_fcs_fabric_s *fabric)
bfa_ioc_get_adapter_model(fabric-fcs-bfa-ioc, model);
 
/* Model name/number */
-   strncpy((char *)port_cfg-node_sym_name, model,
-   BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
-   strncat((char *)port_cfg-node_sym_name,
+   strlcpy((char *)port_cfg-node_sym_name, model,
+   BFA_SYMNAME_MAXLEN);
+   strlcat((char *)port_cfg-node_sym_name,
BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-   sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
+   BFA_SYMNAME_MAXLEN);
 
/* Driver Version */
-   strncat((char *)port_cfg-node_sym_name, (char *)driver_info-version,
-   BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
-   strncat((char *)port_cfg-node_sym_name,
+   strlcat((char *)port_cfg-node_sym_name, (char *)driver_info-version,
+   BFA_SYMNAME_MAXLEN);
+   strlcat((char *)port_cfg-node_sym_name,
BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-   sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
+   BFA_SYMNAME_MAXLEN

[PATCH] scsi: bfa: bfad_attr.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-26 Thread Rickard Strandqvist
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bfa/bfad_attr.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/bfa/bfad_attr.c b/drivers/scsi/bfa/bfad_attr.c
index 40be670..6d21bc6 100644
--- a/drivers/scsi/bfa/bfad_attr.c
+++ b/drivers/scsi/bfa/bfad_attr.c
@@ -842,7 +842,7 @@ bfad_im_symbolic_name_show(struct device *dev, struct 
device_attribute *attr,
char symname[BFA_SYMNAME_MAXLEN];
 
bfa_fcs_lport_get_attr(bfad-bfa_fcs.fabric.bport, port_attr);
-   strncpy(symname, port_attr.port_cfg.sym_name.symname,
+   strlcpy(symname, port_attr.port_cfg.sym_name.symname,
BFA_SYMNAME_MAXLEN);
return snprintf(buf, PAGE_SIZE, %s\n, symname);
 }
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: ibmvscsi: ibmvscsi.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-26 Thread Rickard Strandqvist
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/ibmvscsi/ibmvscsi.c |7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index 7b23f21..b0f5d0a 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -261,7 +261,7 @@ static void gather_partition_info(void)
 
ppartition_name = of_get_property(rootdn, ibm,partition-name, NULL);
if (ppartition_name)
-   strncpy(partition_name, ppartition_name,
+   strlcpy(partition_name, ppartition_name,
sizeof(partition_name));
p_number_ptr = of_get_property(rootdn, ibm,partition-no, NULL);
if (p_number_ptr)
@@ -277,7 +277,7 @@ static void set_adapter_info(struct ibmvscsi_host_data 
*hostdata)
dev_info(hostdata-dev, SRP_VERSION: %s\n, SRP_VERSION);
strcpy(hostdata-madapter_info.srp_version, SRP_VERSION);
 
-   strncpy(hostdata-madapter_info.partition_name, partition_name,
+   strlcpy(hostdata-madapter_info.partition_name, partition_name,
sizeof(hostdata-madapter_info.partition_name));
 
hostdata-madapter_info.partition_number =
@@ -1280,8 +1280,7 @@ static void send_mad_capabilities(struct 
ibmvscsi_host_data *hostdata)
 
location = of_get_property(of_node, ibm,loc-code, NULL);
location = location ? location : dev_name(hostdata-dev);
-   strncpy(hostdata-caps.loc, location, sizeof(hostdata-caps.loc));
-   hostdata-caps.loc[sizeof(hostdata-caps.loc) - 1] = '\0';
+   strlcpy(hostdata-caps.loc, location, sizeof(hostdata-caps.loc));
 
req-common.type = cpu_to_be32(VIOSRP_CAPABILITIES_TYPE);
req-buffer = cpu_to_be64(hostdata-caps_addr);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: qla4xxx: ql4_os.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-26 Thread Rickard Strandqvist
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/qla4xxx/ql4_os.c |   14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 3202063..a07c53e 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -756,9 +756,9 @@ static int qla4xxx_get_chap_list(struct Scsi_Host *shost, 
uint16_t chap_tbl_idx,
continue;
 
chap_rec-chap_tbl_idx = i;
-   strncpy(chap_rec-username, chap_table-name,
+   strlcpy(chap_rec-username, chap_table-name,
ISCSI_CHAP_AUTH_NAME_MAX_LEN);
-   strncpy(chap_rec-password, chap_table-secret,
+   strlcpy(chap_rec-password, chap_table-secret,
QL4_CHAP_MAX_SECRET_LEN);
chap_rec-password_length = chap_table-secret_len;
 
@@ -6027,8 +6027,8 @@ static int qla4xxx_get_bidi_chap(struct scsi_qla_host 
*ha, char *username,
if (!(chap_table-flags  BIT_6)) /* Not BIDI */
continue;
 
-   strncpy(password, chap_table-secret, QL4_CHAP_MAX_SECRET_LEN);
-   strncpy(username, chap_table-name, QL4_CHAP_MAX_NAME_LEN);
+   strlcpy(password, chap_table-secret, QL4_CHAP_MAX_SECRET_LEN);
+   strlcpy(username, chap_table-name, QL4_CHAP_MAX_NAME_LEN);
ret = 0;
break;
}
@@ -6258,8 +6258,8 @@ static void qla4xxx_get_param_ddb(struct ddb_entry 
*ddb_entry,
 
tddb-tpgt = sess-tpgt;
tddb-port = conn-persistent_port;
-   strncpy(tddb-iscsi_name, sess-targetname, ISCSI_NAME_SIZE);
-   strncpy(tddb-ip_addr, conn-persistent_address, DDB_IPADDR_LEN);
+   strlcpy(tddb-iscsi_name, sess-targetname, ISCSI_NAME_SIZE);
+   strlcpy(tddb-ip_addr, conn-persistent_address, DDB_IPADDR_LEN);
 }
 
 static void qla4xxx_convert_param_ddb(struct dev_db_entry *fw_ddb_entry,
@@ -7764,7 +7764,7 @@ static int qla4xxx_sysfs_ddb_logout(struct 
iscsi_bus_flash_session *fnode_sess,
goto exit_ddb_logout;
}
 
-   strncpy(flash_tddb-iscsi_name, fnode_sess-targetname,
+   strlcpy(flash_tddb-iscsi_name, fnode_sess-targetname,
ISCSI_NAME_SIZE);
 
if (!strncmp(fnode_sess-portal_type, PORTAL_TYPE_IPV6, 4))
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: bfa: bfad_bsg.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-26 Thread Rickard Strandqvist
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bfa/bfad_bsg.c |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/bfa/bfad_bsg.c b/drivers/scsi/bfa/bfad_bsg.c
index 8994fb8..f229936 100644
--- a/drivers/scsi/bfa/bfad_bsg.c
+++ b/drivers/scsi/bfa/bfad_bsg.c
@@ -128,7 +128,7 @@ bfad_iocmd_ioc_get_attr(struct bfad_s *bfad, void *cmd)
 
/* fill in driver attr info */
strcpy(iocmd-ioc_attr.driver_attr.driver, BFAD_DRIVER_NAME);
-   strncpy(iocmd-ioc_attr.driver_attr.driver_ver,
+   strlcpy(iocmd-ioc_attr.driver_attr.driver_ver,
BFAD_DRIVER_VERSION, BFA_VERSION_LEN);
strcpy(iocmd-ioc_attr.driver_attr.fw_ver,
iocmd-ioc_attr.adapter_attr.fw_ver);
@@ -316,7 +316,7 @@ bfad_iocmd_port_get_attr(struct bfad_s *bfad, void *cmd)
iocmd-attr.port_type = port_attr.port_type;
iocmd-attr.loopback = port_attr.loopback;
iocmd-attr.authfail = port_attr.authfail;
-   strncpy(iocmd-attr.port_symname.symname,
+   strlcpy(iocmd-attr.port_symname.symname,
port_attr.port_cfg.sym_name.symname,
sizeof(port_attr.port_cfg.sym_name.symname));
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: mpt2sas: mpt2sas_base.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-26 Thread Rickard Strandqvist
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
And removed unnecessary magic numbers.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/mpt2sas/mpt2sas_base.c |   31 +++
 1 file changed, 15 insertions(+), 16 deletions(-)

diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.c 
b/drivers/scsi/mpt2sas/mpt2sas_base.c
index 8b88118..5f0 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.c
@@ -1922,38 +1922,37 @@ _base_display_dell_branding(struct MPT2SAS_ADAPTER *ioc)
if (ioc-pdev-subsystem_vendor != PCI_VENDOR_ID_DELL)
return;
 
-   memset(dell_branding, 0, MPT2SAS_DELL_BRANDING_SIZE);
switch (ioc-pdev-subsystem_device) {
case MPT2SAS_DELL_6GBPS_SAS_HBA_SSDID:
-   strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING,
-   MPT2SAS_DELL_BRANDING_SIZE - 1);
+   strlcpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_HBA_BRANDING,
+   MPT2SAS_DELL_BRANDING_SIZE);
break;
case MPT2SAS_DELL_PERC_H200_ADAPTER_SSDID:
-   strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING,
-   MPT2SAS_DELL_BRANDING_SIZE - 1);
+   strlcpy(dell_branding, MPT2SAS_DELL_PERC_H200_ADAPTER_BRANDING,
+   MPT2SAS_DELL_BRANDING_SIZE);
break;
case MPT2SAS_DELL_PERC_H200_INTEGRATED_SSDID:
-   strncpy(dell_branding,
+   strlcpy(dell_branding,
MPT2SAS_DELL_PERC_H200_INTEGRATED_BRANDING,
-   MPT2SAS_DELL_BRANDING_SIZE - 1);
+   MPT2SAS_DELL_BRANDING_SIZE);
break;
case MPT2SAS_DELL_PERC_H200_MODULAR_SSDID:
-   strncpy(dell_branding,
+   strlcpy(dell_branding,
MPT2SAS_DELL_PERC_H200_MODULAR_BRANDING,
-   MPT2SAS_DELL_BRANDING_SIZE - 1);
+   MPT2SAS_DELL_BRANDING_SIZE);
break;
case MPT2SAS_DELL_PERC_H200_EMBEDDED_SSDID:
-   strncpy(dell_branding,
+   strlcpy(dell_branding,
MPT2SAS_DELL_PERC_H200_EMBEDDED_BRANDING,
-   MPT2SAS_DELL_BRANDING_SIZE - 1);
+   MPT2SAS_DELL_BRANDING_SIZE);
break;
case MPT2SAS_DELL_PERC_H200_SSDID:
-   strncpy(dell_branding, MPT2SAS_DELL_PERC_H200_BRANDING,
-   MPT2SAS_DELL_BRANDING_SIZE - 1);
+   strlcpy(dell_branding, MPT2SAS_DELL_PERC_H200_BRANDING,
+   MPT2SAS_DELL_BRANDING_SIZE);
break;
case MPT2SAS_DELL_6GBPS_SAS_SSDID:
-   strncpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_BRANDING,
-   MPT2SAS_DELL_BRANDING_SIZE - 1);
+   strlcpy(dell_branding, MPT2SAS_DELL_6GBPS_SAS_BRANDING,
+   MPT2SAS_DELL_BRANDING_SIZE);
break;
default:
sprintf(dell_branding, 0x%4X, ioc-pdev-subsystem_device);
@@ -2097,7 +2096,7 @@ _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER 
*ioc)
u32 bios_version;
 
bios_version = le32_to_cpu(ioc-bios_pg3.BiosVersion);
-   strncpy(desc, ioc-manu_pg0.ChipName, 16);
+   strlcpy(desc, ioc-manu_pg0.ChipName, sizeof(desc));
printk(MPT2SAS_INFO_FMT %s: FWVersion(%02d.%02d.%02d.%02d), 
   ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n,
ioc-name, desc,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: mpt3sas: mpt3sas_base.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-26 Thread Rickard Strandqvist
Replacing strncpy with strlcpy to avoid strings that lacks null terminate.
And removed unnecessary magic numbers.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/mpt3sas/mpt3sas_base.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c 
b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 0cf4f70..acc02eb 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -2233,7 +2233,7 @@ _base_display_ioc_capabilities(struct MPT3SAS_ADAPTER 
*ioc)
u32 bios_version;
 
bios_version = le32_to_cpu(ioc-bios_pg3.BiosVersion);
-   strncpy(desc, ioc-manu_pg0.ChipName, 16);
+   strlcpy(desc, ioc-manu_pg0.ChipName, sizeof(desc));
pr_info(MPT3SAS_FMT %s: FWVersion(%02d.%02d.%02d.%02d), \
   ChipRevision(0x%02x), BiosVersion(%02d.%02d.%02d.%02d)\n,
ioc-name, desc,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: scsi_tgt_if.c: Cleaning up missing null-terminate in conjunction with strncpy

2014-07-26 Thread Rickard Strandqvist
If you are going to use memset before strncpy you must copy sizeof -1

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/scsi_tgt_if.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_tgt_if.c b/drivers/scsi/scsi_tgt_if.c
index 6209110..7dc98eb 100644
--- a/drivers/scsi/scsi_tgt_if.c
+++ b/drivers/scsi/scsi_tgt_if.c
@@ -190,7 +190,7 @@ int scsi_tgt_uspace_send_it_nexus_request(int host_no, u64 
itn_id,
ev.p.it_nexus_req.itn_id = itn_id;
if (initiator_id)
strncpy(ev.p.it_nexus_req.initiator_id, initiator_id,
-   sizeof(ev.p.it_nexus_req.initiator_id));
+   sizeof(ev.p.it_nexus_req.initiator_id) - 1);
 
dprintk(%d %x %llx\n, host_no, function, (unsigned long long)itn_id);
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: mpt2sas: mpt2sas_base.c: Fix for possible null pointer dereference

2014-07-03 Thread Rickard Strandqvist
2014-07-03 19:45 GMT+02:00 Joe Lawrence joe.lawre...@stratus.com:
 On Wed, 28 May 2014, Christoph Hellwig wrote:

  -   ioc_status = le16_to_cpu(mpi_reply-IOCStatus)  MPI2_IOCSTATUS_MASK;
  +   if (mpi_reply) {
  +   ioc_status = le16_to_cpu(mpi_reply-IOCStatus)  
  MPI2_IOCSTATUS_MASK;
  +   }
 
  if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  ioc-port_enable_failed = 1;

 ioc_status isn't initialized without the reply and used here as well
 as later in the function.  I think we'll need input from LSI or others
 with the spec on what to do when we didn't get a reply.

 Any update on this?

 The mpt3 version checks for !mpi_reply and returns 1.  Which leads to
 another question -- should mpt{2,3}sas_port_enable_done ever return 0 (as 
 their
 respective comments describe)?

 Regards,

 -- Joe


Hi

Good questions Joe!
And good someone else brought this up, because I guess it's not meant to me.

And it looks however now that I've done quite a few more patches that
there should not have been any {}
And then, it is perhaps good to sett a start value for ioc_status. My
suggestion is:

u16 ioc_status = MPI2_IOCSTATUS_OP_STATE_NOT_SUPPORTED;


Kind regards
Rickard Strandqvist
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2] scsi: bnx2i: bnx2i_iscsi.c: Cleaning up variable is set more than once

2014-06-26 Thread Rickard Strandqvist
A struct member variable is set to different values without having used in 
between.

This was found using a static code analysis program called cppcheck

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bnx2i/bnx2i_iscsi.c |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
index 166543f..4e17a7f 100644
--- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
+++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
@@ -1643,12 +1643,11 @@ static void bnx2i_conn_get_stats(struct iscsi_cls_conn 
*cls_conn,
stats-r2t_pdus = conn-r2t_pdus_cnt;
stats-tmfcmd_pdus = conn-tmfcmd_pdus_cnt;
stats-tmfrsp_pdus = conn-tmfrsp_pdus_cnt;
-   stats-custom_length = 3;
strcpy(stats-custom[2].desc, eh_abort_cnt);
stats-custom[2].value = conn-eh_abort_cnt;
stats-digest_err = 0;
stats-timeout_err = 0;
-   stats-custom_length = 0;
+   stats-custom_length = 3;
 }
 
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] scsi: bnx2i: bnx2i_iscsi.c: Fix variable which was set to the wrong value

2014-06-26 Thread Rickard Strandqvist
After some discussion, all agreed that the previous value was incorrect.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bnx2i/bnx2i_iscsi.c |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
index 166543f..4e17a7f 100644
--- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
+++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
@@ -1643,12 +1643,11 @@ static void bnx2i_conn_get_stats(struct iscsi_cls_conn 
*cls_conn,
stats-r2t_pdus = conn-r2t_pdus_cnt;
stats-tmfcmd_pdus = conn-tmfcmd_pdus_cnt;
stats-tmfrsp_pdus = conn-tmfrsp_pdus_cnt;
-   stats-custom_length = 3;
strcpy(stats-custom[2].desc, eh_abort_cnt);
stats-custom[2].value = conn-eh_abort_cnt;
stats-digest_err = 0;
stats-timeout_err = 0;
-   stats-custom_length = 0;
+   stats-custom_length = 3;
 }
 
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: advansys.c: Cleaning up variable is set more than once

2014-06-25 Thread Rickard Strandqvist
A struct member variable is set to the same value more than once

This was found using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/advansys.c |2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index d814588..8281ae0 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -11592,7 +11592,6 @@ static int advansys_board_found(struct Scsi_Host 
*shost, unsigned int iop,
adv_dvc_varp-cfg-disc_enable;
ep_38C0800-bios_ctrl = adv_dvc_varp-bios_ctrl;
ep_38C0800-wdtr_able = adv_dvc_varp-wdtr_able;
-   ep_38C0800-tagqng_able = adv_dvc_varp-tagqng_able;
ep_38C0800-sdtr_speed1 = adv_dvc_varp-sdtr_speed1;
ep_38C0800-sdtr_speed2 = adv_dvc_varp-sdtr_speed2;
ep_38C0800-sdtr_speed3 = adv_dvc_varp-sdtr_speed3;
@@ -11620,7 +11619,6 @@ static int advansys_board_found(struct Scsi_Host 
*shost, unsigned int iop,
adv_dvc_varp-cfg-disc_enable;
ep_38C1600-bios_ctrl = adv_dvc_varp-bios_ctrl;
ep_38C1600-wdtr_able = adv_dvc_varp-wdtr_able;
-   ep_38C1600-tagqng_able = adv_dvc_varp-tagqng_able;
ep_38C1600-sdtr_speed1 = adv_dvc_varp-sdtr_speed1;
ep_38C1600-sdtr_speed2 = adv_dvc_varp-sdtr_speed2;
ep_38C1600-sdtr_speed3 = adv_dvc_varp-sdtr_speed3;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: pm8001: pm80xx_hwi.c: Cleaning up variable is set more than once

2014-06-25 Thread Rickard Strandqvist
A struct member variable is set to different values without having used in 
between.

This was found using a static code analysis program called cppcheck

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/pm8001/pm80xx_hwi.c |1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/pm8001/pm80xx_hwi.c b/drivers/scsi/pm8001/pm80xx_hwi.c
index d70587f..2698227 100644
--- a/drivers/scsi/pm8001/pm80xx_hwi.c
+++ b/drivers/scsi/pm8001/pm80xx_hwi.c
@@ -249,7 +249,6 @@ moreData:
sprintf(pm8001_ha-
forensic_info.data_buf.direct_data,
%08x , 4);
-   pm8001_ha-forensic_info.data_buf.read_len = 0x;
pm8001_ha-forensic_info.data_buf.direct_len =  0;
pm8001_ha-forensic_info.data_buf.direct_offset = 0;
pm8001_ha-forensic_info.data_buf.read_len = 0;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: bnx2i: bnx2i_iscsi.c: Cleaning up variable is set more than once

2014-06-25 Thread Rickard Strandqvist
A struct member variable is set to different values without having used in 
between.

This was found using a static code analysis program called cppcheck

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bnx2i/bnx2i_iscsi.c |1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
index 166543f..fdf7bc3 100644
--- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
+++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
@@ -1643,7 +1643,6 @@ static void bnx2i_conn_get_stats(struct iscsi_cls_conn 
*cls_conn,
stats-r2t_pdus = conn-r2t_pdus_cnt;
stats-tmfcmd_pdus = conn-tmfcmd_pdus_cnt;
stats-tmfrsp_pdus = conn-tmfrsp_pdus_cnt;
-   stats-custom_length = 3;
strcpy(stats-custom[2].desc, eh_abort_cnt);
stats-custom[2].value = conn-eh_abort_cnt;
stats-digest_err = 0;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: bnx2i: bnx2i_iscsi.c: Cleaning up variable is set more than once

2014-06-25 Thread Rickard Strandqvist
2014-06-25 19:13 GMT+02:00 Eddie Wai eddie@broadcom.com:
 On Wed, 2014-06-25 at 16:26 +0200, Maurizio Lombardi wrote:
 Hi,

 On 06/25/2014 04:04 PM, Rickard Strandqvist wrote:
  A struct member variable is set to different values without having used in 
  between.
 
  This was found using a static code analysis program called cppcheck
 
  Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
  ---
   drivers/scsi/bnx2i/bnx2i_iscsi.c |1 -
   1 file changed, 1 deletion(-)
 
  diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c 
  b/drivers/scsi/bnx2i/bnx2i_iscsi.c
  index 166543f..fdf7bc3 100644
  --- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
  +++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
  @@ -1643,7 +1643,6 @@ static void bnx2i_conn_get_stats(struct 
  iscsi_cls_conn *cls_conn,
  stats-r2t_pdus = conn-r2t_pdus_cnt;
  stats-tmfcmd_pdus = conn-tmfcmd_pdus_cnt;
  stats-tmfrsp_pdus = conn-tmfrsp_pdus_cnt;
  -   stats-custom_length = 3;
  strcpy(stats-custom[2].desc, eh_abort_cnt);
  stats-custom[2].value = conn-eh_abort_cnt;
  stats-digest_err = 0;
 

 Eddie,

 The code modifies the content of stats-custom[2], so shouldn't 
 custom_length be set to 3?
 Why is it set to zero at the end of this function?
 Nice find.  This is literally a day1 bug.  Yes, I agree that the
 custom_length should be left at 3.  Otherwise, the nlmsg replied back to
 the application would not have the custom message.  Thanks.

 Regards,
 Maurizio Lombardi




Hi, and thank you!

If it's not obvious, I do all my fixes without changing the previous
intent. But obviously it is not always right, rather it is one of main
reasons to fix this type of error :)

But I'll make a new patch then, with = 3 ?


Kind regards
Rickard Strandqvist
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: mpt3sas: mpt3sas_base.c: Cleaning up wrong return value

2014-06-07 Thread Rickard Strandqvist
A variable to manage the error code is not returned.

This was partly found using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/mpt3sas/mpt3sas_base.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/mpt3sas/mpt3sas_base.c 
b/drivers/scsi/mpt3sas/mpt3sas_base.c
index 0cf4f70..1140b0a 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_base.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_base.c
@@ -3715,7 +3715,7 @@ _base_send_ioc_init(struct MPT3SAS_ADAPTER *ioc, int 
sleep_flag)
r = -EIO;
}
 
-   return 0;
+   return r;
 }
 
 /**
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: bfa: bfad_attr.c: Cleaning up missing null-terminate after strncpy call

2014-06-06 Thread Rickard Strandqvist
Hi

Now I have some time to check on this.
I do not make a fuss or anything, but thought nonetheless provide some feedback.

1) I did not know that Linux had strlcpy, much better choice, of course!

2) It was not clear that this was done in the code. And my thought
was, rather, just that you were not sure if there was a null character
because it used strlcpy. if this can not possibly happen would be
almost as well to switch to strcpy outright.

3) Have now checked a little deeper, but do not see the solution you
mention really.
In the function bfa_fcs_fdmi_get_portattr() a memset NULL the whole
incoming struct.

But the only thing that is done then is a:

strncpy(port_attr-port_sym_name.symname,
(char *)bfa_fcs_lport_get_psym_name(port), BFA_SYMNAME_MAXLEN);

Thus not having BFA_SYMNAME_MAXLEN -1  that would be a solution.




Best regards
Rickard Strandqvist


2014-06-04 23:59 GMT+02:00 James Bottomley
james.bottom...@hansenpartnership.com:
 On Wed, 2014-06-04 at 23:32 +0200, Rickard Strandqvist wrote:
 Added a guaranteed null-terminate after call to strncpy.

 This was partly found using a static code analysis program called cppcheck.

 Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
 ---
  drivers/scsi/bfa/bfad_attr.c |3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

 diff --git a/drivers/scsi/bfa/bfad_attr.c b/drivers/scsi/bfa/bfad_attr.c
 index 40be670..06aa3dd 100644
 --- a/drivers/scsi/bfa/bfad_attr.c
 +++ b/drivers/scsi/bfa/bfad_attr.c
 @@ -843,7 +843,8 @@ bfad_im_symbolic_name_show(struct device *dev, struct 
 device_attribute *attr,

   bfa_fcs_lport_get_attr(bfad-bfa_fcs.fabric.bport, port_attr);
   strncpy(symname, port_attr.port_cfg.sym_name.symname,
 - BFA_SYMNAME_MAXLEN);
 + sizeof(symname));
 + symname[sizeof(symname) - 1] = '\0';

 So actually, this isn't the correct pattern for this type of potential
 problem, where the problem exists, the pattern is to replace strncpy()
 with strlcpy() which does a correct null termination on truncation.

 In this case I presume your static checker isn't sufficiently clever to
 see that there isn't a bug because port_attr.port_cfg.sym_name.symname
 is carefully copied to be NULL terminated and always less than
 BFA_SYMNAME_MAXLEN, so when copying out of it we can rely on the NULL
 termination fitting into BFA_SYMNAME_MAXLEN.

 James


--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: mpt2sas: mpt2sas_base.c: Cleaning up missing null-terminate after strncpy call

2014-06-06 Thread Rickard Strandqvist
Hi

I did not know that Linux had strlcpy, much better choice, of course!

It was not clear that this was done in the code. And my thought was,
rather, just that you were not sure if there was a null character
because it used strlcpy. if this can not possibly happen would be
almost as well to switch to strcpy outright.

So what happens now?
Should I make a new patch, with strlcpy or just straight off with strcpy then?



Best regards
Rickard Strandqvist


2014-06-05 0:28 GMT+02:00 James Bottomley
james.bottom...@hansenpartnership.com:
 On Wed, 2014-06-04 at 23:36 +0200, Rickard Strandqvist wrote:
 Added a guaranteed null-terminate after call to strncpy.

 This was partly found using a static code analysis program called cppcheck.

 Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
 ---
  drivers/scsi/mpt2sas/mpt2sas_base.c |3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

 diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.c 
 b/drivers/scsi/mpt2sas/mpt2sas_base.c
 index bde63f7..4c3eceb 100644
 --- a/drivers/scsi/mpt2sas/mpt2sas_base.c
 +++ b/drivers/scsi/mpt2sas/mpt2sas_base.c
 @@ -2097,7 +2097,8 @@ _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER 
 *ioc)
   u32 bios_version;

   bios_version = le32_to_cpu(ioc-bios_pg3.BiosVersion);
 - strncpy(desc, ioc-manu_pg0.ChipName, 16);
 + strncpy(desc, ioc-manu_pg0.ChipName, sizeof(desc));
 + desc[sizeof(desc) - 1] = '\0';

 There's no bug here because the specs define the ChipName field of the
 manufacturing page 0 to be 16 bytes and null terminated.  The nasty part
 is the way this driver is littered with magic numbers.

 James


--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: bfa: bfad_attr.c: Optimization of the code

2014-06-06 Thread Rickard Strandqvist
Minimized the use of snprintf()
And removed a variable that was only used for the temporary storage.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bfa/bfad_attr.c |  114 --
 1 file changed, 66 insertions(+), 48 deletions(-)

diff --git a/drivers/scsi/bfa/bfad_attr.c b/drivers/scsi/bfa/bfad_attr.c
index 40be670..3fe75ff 100644
--- a/drivers/scsi/bfa/bfad_attr.c
+++ b/drivers/scsi/bfa/bfad_attr.c
@@ -751,69 +751,89 @@ bfad_im_model_desc_show(struct device *dev, struct 
device_attribute *attr,
bfa_get_adapter_model(bfad-bfa, model);
nports = bfa_get_nports(bfad-bfa);
if (!strcmp(model, Brocade-425))
-   snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
-   Brocade 4Gbps PCIe dual port FC HBA);
+   strlcpy(model_descr,
+   Brocade 4Gbps PCIe dual port FC HBA\n,
+   BFA_ADAPTER_MODEL_DESCR_LEN);
else if (!strcmp(model, Brocade-825))
-   snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
-   Brocade 8Gbps PCIe dual port FC HBA);
+   strlcpy(model_descr,
+   Brocade 8Gbps PCIe dual port FC HBA\n,
+   BFA_ADAPTER_MODEL_DESCR_LEN);
else if (!strcmp(model, Brocade-42B))
-   snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
-   Brocade 4Gbps PCIe dual port FC HBA for HP);
+   strlcpy(model_descr,
+   Brocade 4Gbps PCIe dual port FC HBA for HP\n,
+   BFA_ADAPTER_MODEL_DESCR_LEN);
else if (!strcmp(model, Brocade-82B))
-   snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
-   Brocade 8Gbps PCIe dual port FC HBA for HP);
+   strlcpy(model_descr,
+   Brocade 8Gbps PCIe dual port FC HBA for HP\n,
+   BFA_ADAPTER_MODEL_DESCR_LEN);
else if (!strcmp(model, Brocade-1010))
-   snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
-   Brocade 10Gbps single port CNA);
+   strlcpy(model_descr,
+   Brocade 10Gbps single port CNA\n,
+   BFA_ADAPTER_MODEL_DESCR_LEN);
else if (!strcmp(model, Brocade-1020))
-   snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
-   Brocade 10Gbps dual port CNA);
+   strlcpy(model_descr,
+   Brocade 10Gbps dual port CNA\n,
+   BFA_ADAPTER_MODEL_DESCR_LEN);
else if (!strcmp(model, Brocade-1007))
-   snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
-   Brocade 10Gbps CNA for IBM Blade Center);
+   strlcpy(model_descr,
+   Brocade 10Gbps CNA for IBM Blade Center\n,
+   BFA_ADAPTER_MODEL_DESCR_LEN);
else if (!strcmp(model, Brocade-415))
-   snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
-   Brocade 4Gbps PCIe single port FC HBA);
+   strlcpy(model_descr,
+   Brocade 4Gbps PCIe single port FC HBA\n,
+   BFA_ADAPTER_MODEL_DESCR_LEN);
else if (!strcmp(model, Brocade-815))
-   snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
-   Brocade 8Gbps PCIe single port FC HBA);
+   strlcpy(model_descr,
+   Brocade 8Gbps PCIe single port FC HBA\n,
+   BFA_ADAPTER_MODEL_DESCR_LEN);
else if (!strcmp(model, Brocade-41B))
-   snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
-   Brocade 4Gbps PCIe single port FC HBA for HP);
+   strlcpy(model_descr,
+   Brocade 4Gbps PCIe single port FC HBA for 
HP\n,
+   BFA_ADAPTER_MODEL_DESCR_LEN);
else if (!strcmp(model, Brocade-81B))
-   snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
-   Brocade 8Gbps PCIe single port FC HBA for HP);
+   strlcpy(model_descr,
+   Brocade 8Gbps PCIe single port FC HBA for 
HP\n,
+   BFA_ADAPTER_MODEL_DESCR_LEN);
else if (!strcmp(model, Brocade-804))
-   snprintf(model_descr, BFA_ADAPTER_MODEL_DESCR_LEN,
-   Brocade 8Gbps FC HBA for HP Bladesystem C-class);
+   strlcpy(model_descr,
+   Brocade 8Gbps FC HBA for HP Bladesystem 
C-class\n,
+   BFA_ADAPTER_MODEL_DESCR_LEN);
else if (!strcmp(model, Brocade-1741))
-   snprintf(model_descr

Re: [PATCH] scsi: bfa: bfad_attr.c: Optimization of the Code

2014-06-06 Thread Rickard Strandqvist
Hi

Several have remarked in the other patch for strncpy I posted. That
there is a strlcpy that works exactly as one would like to strncpy was
done :)
And the return value is like for snprintf, but quite a lot faster!

So I submit patches based with it instead, and did a couple more
exchanges of snprintf to strlcpy.



Best regards
Rickard Strandqvist


2014-06-05 9:10 GMT+02:00 Bart Van Assche bvanass...@acm.org:
 On 06/05/14 08:55, Bart Van Assche wrote:
 On 06/04/14 20:08, Rickard Strandqvist wrote:
 This is ugly. Please use sprintf(buf, %.*s\n, PAGE_SIZE - 1, str)
 instead of strncpy() + strlen().

 (replying to my own e-mail)

 The above should of course have read sprintf(buf, %.*s\n, PAGE_SIZE -
 2, str) to avoid that the terminating '\0' triggers a buffer overflow.

 Bart.
--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: bfa: bfad_attr.c: Optimization of the Code

2014-06-04 Thread Rickard Strandqvist
Minimized the use of snprintf()
And removed a variable that was only used for the temporary storage.

This was partly found using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bfa/bfad_attr.c |   14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/bfa/bfad_attr.c b/drivers/scsi/bfa/bfad_attr.c
index 40be670..5f5917a 100644
--- a/drivers/scsi/bfa/bfad_attr.c
+++ b/drivers/scsi/bfa/bfad_attr.c
@@ -839,12 +839,10 @@ bfad_im_symbolic_name_show(struct device *dev, struct 
device_attribute *attr,
(struct bfad_im_port_s *) shost-hostdata[0];
struct bfad_s *bfad = im_port-bfad;
struct bfa_lport_attr_s port_attr;
-   char symname[BFA_SYMNAME_MAXLEN];
 
bfa_fcs_lport_get_attr(bfad-bfa_fcs.fabric.bport, port_attr);
-   strncpy(symname, port_attr.port_cfg.sym_name.symname,
-   BFA_SYMNAME_MAXLEN);
-   return snprintf(buf, PAGE_SIZE, %s\n, symname);
+   return snprintf(buf, PAGE_SIZE, %s\n,
+   port_attr.port_cfg.sym_name.symname);
 }
 
 static ssize_t
@@ -865,7 +863,9 @@ static ssize_t
 bfad_im_drv_version_show(struct device *dev, struct device_attribute *attr,
char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, %s\n, BFAD_DRIVER_VERSION);
+   strncpy(buf, BFAD_DRIVER_VERSION  \n , PAGE_SIZE);
+   buf[PAGE_SIZE - 1] = '\0';
+   return strlen(buf);
 }
 
 static ssize_t
@@ -913,7 +913,9 @@ static ssize_t
 bfad_im_drv_name_show(struct device *dev, struct device_attribute *attr,
char *buf)
 {
-   return snprintf(buf, PAGE_SIZE, %s\n, BFAD_DRIVER_NAME);
+   strncpy(buf, BFAD_DRIVER_NAME  \n , PAGE_SIZE);
+   buf[PAGE_SIZE - 1] = '\0';
+   return strlen(buf);
 }
 
 static ssize_t
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: bfa: bfad_attr.c: Cleaning up missing null-terminate after strncpy call

2014-06-04 Thread Rickard Strandqvist
Added a guaranteed null-terminate after call to strncpy.

This was partly found using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bfa/bfad_attr.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/bfa/bfad_attr.c b/drivers/scsi/bfa/bfad_attr.c
index 40be670..06aa3dd 100644
--- a/drivers/scsi/bfa/bfad_attr.c
+++ b/drivers/scsi/bfa/bfad_attr.c
@@ -843,7 +843,8 @@ bfad_im_symbolic_name_show(struct device *dev, struct 
device_attribute *attr,
 
bfa_fcs_lport_get_attr(bfad-bfa_fcs.fabric.bport, port_attr);
strncpy(symname, port_attr.port_cfg.sym_name.symname,
-   BFA_SYMNAME_MAXLEN);
+   sizeof(symname));
+   symname[sizeof(symname) - 1] = '\0';
return snprintf(buf, PAGE_SIZE, %s\n, symname);
 }
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: mpt2sas: mpt2sas_base.c: Cleaning up missing null-terminate after strncpy call

2014-06-04 Thread Rickard Strandqvist
Hi

A little embarrassing, but I actually did not know that there was a
better replacement for strncpy.

Sorry, but I will send a new platch based on strlcpy instead then.

Will investigate cover letter then to.


Best regards
Rickard Strandqvist


2014-06-05 0:01 GMT+02:00 Joe Perches j...@perches.com:
 On Wed, 2014-06-04 at 23:36 +0200, Rickard Strandqvist wrote:
 Added a guaranteed null-terminate after call to strncpy.

 Next time you submit a patch series like this
 can you please use a cover letter?

 That way I can reply to the cover letter with
 a comment about the series instead of multiple
 replies to various patches.

 I think all of these should be using strlcpy not
 strncpy.

 diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.c 
 b/drivers/scsi/mpt2sas/mpt2sas_base.c
 []
 @@ -2097,7 +2097,8 @@ _base_display_ioc_capabilities(struct MPT2SAS_ADAPTER 
 *ioc)
   u32 bios_version;

   bios_version = le32_to_cpu(ioc-bios_pg3.BiosVersion);
 - strncpy(desc, ioc-manu_pg0.ChipName, 16);
 + strncpy(desc, ioc-manu_pg0.ChipName, sizeof(desc));
 + desc[sizeof(desc) - 1] = '\0';


--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: pm8001: pm8001_hwi.c: Fix for possible null pointer dereference

2014-05-29 Thread Rickard Strandqvist
Hi

Quite rightly, this is what cppcheck reacts.
Ok, I'll send a patch for that instead then.


Best regards
Rickard Strandqvist


2014-05-28 13:38 GMT+02:00 Tomas Henzl the...@redhat.com:
 On 05/28/2014 01:28 PM, Christoph Hellwig wrote:
 On Sun, May 18, 2014 at 06:14:00PM +0200, Rickard Strandqvist wrote:
 There is otherwise a risk of a possible null pointer dereference.

 Was largely found by using a static code analysis program called cppcheck.
 I can't see how dev-lldd_dev would be NULL here.

 The analysis program likely can't know that, the reason for this report
 it that dev-lldd_dev is tested for not being null several lines below -
 http://lxr.free-electrons.com/source/drivers/scsi/pm8001/pm8001_hwi.c#L4447
 So the other option is to remove this^ test.

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: pm8001: pm8001_hwi.c: Fix to remove null pointer checks that could never happen

2014-05-29 Thread Rickard Strandqvist
Removal of null pointer checks that could never happen

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/pm8001/pm8001_hwi.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/pm8001/pm8001_hwi.c b/drivers/scsi/pm8001/pm8001_hwi.c
index a97be01..721d059 100644
--- a/drivers/scsi/pm8001/pm8001_hwi.c
+++ b/drivers/scsi/pm8001/pm8001_hwi.c
@@ -4398,7 +4398,7 @@ static int pm8001_chip_sata_req(struct pm8001_hba_info 
*pm8001_ha,
 
/* Check for read log for failed drive and return */
if (sata_cmd.sata_fis.command == 0x2f) {
-   if (pm8001_ha_dev  ((pm8001_ha_dev-id  NCQ_READ_LOG_FLAG) ||
+   if (((pm8001_ha_dev-id  NCQ_READ_LOG_FLAG) ||
(pm8001_ha_dev-id  NCQ_ABORT_ALL_FLAG) ||
(pm8001_ha_dev-id  NCQ_2ND_RLE_FLAG))) {
struct task_status_struct *ts;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: dc395x.c: Fix for possible null pointer dereference

2014-05-20 Thread Rickard Strandqvist
Okay, good!
Or, do I need to do anything else :-)

Best regards
Rickard Strandqvist


2014-05-19 13:39 GMT+02:00 Oliver Neukum oneu...@suse.de:
 On Sun, 2014-05-18 at 21:50 +0200, Guennadi Liakhovetski wrote:
 On Sun, 18 May 2014, Rickard Strandqvist wrote:

  There is otherwise a risk of a possible null pointer dereference.
 
  Was largely found by using a static code analysis program called cppcheck.
 
  Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
  ---
   drivers/scsi/dc395x.c |2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
 
  diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
  index 83d9bf6..0d86bc7 100644
  --- a/drivers/scsi/dc395x.c
  +++ b/drivers/scsi/dc395x.c
  @@ -2637,7 +2637,7 @@ static struct ScsiReqBlk *msgin_qtag(struct 
  AdapterCtlBlk *acb,
  struct ScsiReqBlk *srb = NULL;
  struct ScsiReqBlk *i;
  dprintkdbg(DBG_0, msgin_qtag: (0x%p) tag=%i srb=%p\n,
  -  srb-cmd, tag, srb);
  +  srb ? srb-cmd : 0, tag, srb);

 There's not just a risk, it is a NULL-pointer dereference, so, just remove
 it, e.g. like

 Indeed. Thank you both for catching this.

 Regards
 Oliver



--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] message: fusion: mptscsih.c: Fix for possible null pointer dereference

2014-05-18 Thread Rickard Strandqvist
There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/message/fusion/mptscsih.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/message/fusion/mptscsih.c 
b/drivers/message/fusion/mptscsih.c
index 727819c..b323b23 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -1279,9 +1279,11 @@ mptscsih_info(struct Scsi_Host *SChost)
 
mpt_print_ioc_summary(h-ioc, h-info_kbuf, size, 0, 0);
h-info_kbuf[size-1] = '\0';
+
+   return h-info_kbuf;
}
 
-   return h-info_kbuf;
+   return NULL;
 }
 
 int mptscsih_show_info(struct seq_file *m, struct Scsi_Host *host)
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: bfa: bfa_fcs_lport.c: Fix for possible null pointer dereference

2014-05-18 Thread Rickard Strandqvist
There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bfa/bfa_fcs_lport.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
index ff75ef8..542d5c6 100644
--- a/drivers/scsi/bfa/bfa_fcs_lport.c
+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
@@ -5826,12 +5826,13 @@ bfa_fcs_lport_get_rport_max_speed(bfa_fcs_lport_t *port)
bfa_port_speed_t max_speed = 0;
struct bfa_port_attr_s port_attr;
bfa_port_speed_t port_speed, rport_speed;
-   bfa_boolean_t trl_enabled = bfa_fcport_is_ratelim(port-fcs-bfa);
+   bfa_boolean_t trl_enabled;
 
 
if (port == NULL)
return 0;
 
+   trl_enabled = bfa_fcport_is_ratelim(port-fcs-bfa);
fcs = port-fcs;
 
/* Get Physical port's current speed */
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: bnx2i: bnx2i_iscsi.c: Fix for possible null pointer dereference

2014-05-18 Thread Rickard Strandqvist
There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/bnx2i/bnx2i_iscsi.c |5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c
index 166543f..3df26ac 100644
--- a/drivers/scsi/bnx2i/bnx2i_iscsi.c
+++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c
@@ -237,7 +237,10 @@ static int bnx2i_bind_conn_to_iscsi_cid(struct bnx2i_hba 
*hba,
struct bnx2i_conn *bnx2i_conn,
u32 iscsi_cid)
 {
-   if (hba  hba-cid_que.conn_cid_tbl[iscsi_cid]) {
+   if(!hba)
+   return -EFAULT;
+
+   if (hba-cid_que.conn_cid_tbl[iscsi_cid]) {
iscsi_conn_printk(KERN_ALERT, bnx2i_conn-cls_conn-dd_data,
 conn bind - entry #%d not free\n, iscsi_cid);
return -EBUSY;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: dc395x.c: Fix for possible null pointer dereference

2014-05-18 Thread Rickard Strandqvist
There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/dc395x.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index 83d9bf6..0d86bc7 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -2637,7 +2637,7 @@ static struct ScsiReqBlk *msgin_qtag(struct AdapterCtlBlk 
*acb,
struct ScsiReqBlk *srb = NULL;
struct ScsiReqBlk *i;
dprintkdbg(DBG_0, msgin_qtag: (0x%p) tag=%i srb=%p\n,
-  srb-cmd, tag, srb);
+  srb ? srb-cmd : 0, tag, srb);
 
if (!(dcb-tag_mask  (1  tag)))
dprintkl(KERN_DEBUG,
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: mpt2sas: mpt2sas_base.c: Fix for possible null pointer dereference

2014-05-18 Thread Rickard Strandqvist
There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/mpt2sas/mpt2sas_base.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.c 
b/drivers/scsi/mpt2sas/mpt2sas_base.c
index bde63f7..7ccc7e4 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.c
@@ -3581,7 +3581,9 @@ mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 
smid, u8 msix_index,
}
ioc-port_enable_cmds.status = ~MPT2_CMD_PENDING;
 
-   ioc_status = le16_to_cpu(mpi_reply-IOCStatus)  MPI2_IOCSTATUS_MASK;
+   if (mpi_reply) {
+   ioc_status = le16_to_cpu(mpi_reply-IOCStatus)  
MPI2_IOCSTATUS_MASK;
+   }
 
if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
ioc-port_enable_failed = 1;
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: mvsas: mv_sas.c: Fix for possible null pointer dereference

2014-05-18 Thread Rickard Strandqvist
There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/mvsas/mv_sas.c |   24 ++--
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/drivers/scsi/mvsas/mv_sas.c b/drivers/scsi/mvsas/mv_sas.c
index 6c1f223..ac52f7c 100644
--- a/drivers/scsi/mvsas/mv_sas.c
+++ b/drivers/scsi/mvsas/mv_sas.c
@@ -1344,19 +1344,23 @@ void mvs_dev_gone_notify(struct domain_device *dev)
 {
unsigned long flags = 0;
struct mvs_device *mvi_dev = dev-lldd_dev;
-   struct mvs_info *mvi = mvi_dev-mvi_info;
-
-   spin_lock_irqsave(mvi-lock, flags);
+   struct mvs_info *mvi;
 
-   if (mvi_dev) {
-   mv_dprintk(found dev[%d:%x] is gone.\n,
-   mvi_dev-device_id, mvi_dev-dev_type);
-   mvs_release_task(mvi, dev);
-   mvs_free_reg_set(mvi, mvi_dev);
-   mvs_free_dev(mvi_dev);
-   } else {
+   if (!mvi_dev) {
mv_dprintk(found dev has gone.\n);
+   return;
}
+
+   mvi = mvi_dev-mvi_info;
+
+   spin_lock_irqsave(mvi-lock, flags);
+
+   mv_dprintk(found dev[%d:%x] is gone.\n,
+   mvi_dev-device_id, mvi_dev-dev_type);
+   mvs_release_task(mvi, dev);
+   mvs_free_reg_set(mvi, mvi_dev);
+   mvs_free_dev(mvi_dev);
+
dev-lldd_dev = NULL;
mvi_dev-sas_device = NULL;
 
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi: pm8001: pm8001_hwi.c: Fix for possible null pointer dereference

2014-05-18 Thread Rickard Strandqvist
There is otherwise a risk of a possible null pointer dereference.

Was largely found by using a static code analysis program called cppcheck.

Signed-off-by: Rickard Strandqvist rickard_strandqv...@spectrumdigital.se
---
 drivers/scsi/pm8001/pm8001_hwi.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/pm8001/pm8001_hwi.c b/drivers/scsi/pm8001/pm8001_hwi.c
index a97be01..60a988c 100644
--- a/drivers/scsi/pm8001/pm8001_hwi.c
+++ b/drivers/scsi/pm8001/pm8001_hwi.c
@@ -4367,7 +4367,8 @@ static int pm8001_chip_sata_req(struct pm8001_hba_info 
*pm8001_ha,
}
dir = data_dir_flags[task-data_dir]  8;
sata_cmd.tag = cpu_to_le32(tag);
-   sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev-device_id);
+   if(pm8001_ha_dev)
+   sata_cmd.device_id = cpu_to_le32(pm8001_ha_dev-device_id);
sata_cmd.data_len = cpu_to_le32(task-total_xfer_len);
sata_cmd.ncqtag_atap_dir_m =
cpu_to_le32(((ncg_tag  0xff)16)|((ATAP  0x3f)  10) | dir);
-- 
1.7.10.4

--
To unsubscribe from this list: send the line unsubscribe linux-scsi in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html