The deck guns were perfectly capable against planes.
"The 4 inch 50 caliber dual purpose cannon was standard issue to many submarines during World War II. This weapon had a muzzle velocity of 2,700 feet per second, a maximum range of 14,600 yards and was equally effective being utilized against both surface and aerial targets."
From this nice sites article on Deck Guns
http://www.valoratsea.com/arms1.htm