When my controller has a failed disk, megasasctl fails.
# megasasctl me so crazy, me think adapter crazy too. sorry, mister. /usr/sbin/megasasctl: line 15: 28073 Segmentation fault /usr/lib/megactl/megasasctl $@
I have tracked the problem down to a bad assumption, that the various disk enumeration loops would use the number of currently online drives as the basis for the iterator.
This number decreases when a disk fails. It is not noticeable in many cases, because on many some controllers pinfo->pd_present_count is one higher than the actual number of disks. However, the same situation would be encountered in a RAID1 system with two failed disks.
The attached one-line patch uses the number of ports on the controller as the basis.